home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / sharew / musik / cdsound / csoundok.lzh / CSOUND.TXT next >
Encoding:
Text File  |  1995-12-14  |  309.8 KB  |  7,657 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.                                 Csound
  7.                                    
  8.                                    
  9.                                    
  10.                                    
  11.                                    
  12.                                    
  13.                A Manual for the Audio Processing System
  14.                                    
  15.                                  and
  16.                                    
  17.                          Supporting Programs
  18.                                    
  19.                                  with
  20.                                    
  21.                               Tutorials
  22.                                    
  23.                                    
  24.                                    
  25.                                    
  26.                                    
  27.                                    
  28.                                    
  29.                                    
  30.                                    
  31.                              Barry Vercoe
  32.                               Media Lab
  33.                                 M.I.T.
  34.  
  35.                                 Csound
  36.                                    
  37.                                    
  38.                                    
  39.                A Manual for the Audio Processing System
  40.                                    
  41.                                  and
  42.                                    
  43.                          Supporting Programs
  44.                                    
  45.                                  with
  46.                                    
  47.                               Tutorials
  48.                                    
  49.                                    
  50.                                    
  51.                              Barry Vercoe
  52.                               Media Lab
  53.                                 M.I.T.
  54.  
  55.  
  56.  
  57.  
  58. Copyright 1986, 1992 by the Massachusetts Institute of
  59. Technology.  All rights reserved.
  60.  
  61. Developed by Barry L. Vercoe at the Experimental Music Studio,
  62. Media Laboratory, M.I.T., Cambridge, Massachusetts,
  63. with partial support from the System Development Foundation
  64. and from National Science Foundation Grant # IRI-8704665.
  65.  
  66. --------------------------------------------------------------------
  67.  
  68. Permission to use, copy, or modify these programs and their
  69. documentation for educational and research purposes only and
  70. without fee is hereby granted, provided that this copyright and
  71. permission notice appear on all copies and supporting
  72. documentation.  For any other uses of this software, in original
  73. or modified form, including but not limited to distribution in
  74. whole or in part, specific prior permission from M.I.T. must be
  75. obtained.  M.I.T. makes no representations about the suitability
  76. of this software for any purpose.  It is provided "as is" without
  77. express or implied warranty.
  78.  
  79. --------------------------------------------------------------------
  80.  
  81. CONTENTS
  82.  
  83. 0.  PREFACE                                                                v
  84.  
  85. 1.  A BEGINNING TUTORIAL                                                       1
  86.      Introduction                                                       1
  87.      The Orchestra File                                                 1
  88.      The Score File                                                         3
  89.      The csound Command                                                     5
  90.      More about the Orchestra                                           6
  91.  
  92. 2.  SYNTAX OF THE ORCHESTRA                                                    7
  93.      STATEMENT TYPES                                                        7
  94.      CONSTANTS AND VARIABLES                                                8
  95.      VALUE CONVERTERS:  int, frac, abs, ftlen, i,
  96.           exp, log, sqrt, sin, cos, dbamp, ampdb                        9
  97.      PITCH CONVERTERS:  octpch, pchoct,
  98.           cpspch, octcps, cpsoct                                        10
  99.      ARITHMETIC OPERATIONS                                                  11
  100.      CONDITIONAL VALUES                                                     11
  101.      EXPRESSIONS                                                            12
  102.      DIRECTORIES and FILES;  NOMENCLATURE                               12
  103.      ASSIGNMENT STATEMENTS:  =, init, tival, divz                       13
  104.      ORCHESTRA HEADER:  sr, kr, ksmps, nchnls                           14
  105.      INSTRUMENT BLOCKS: instr, endin                                    15
  106.      PROGRAM CONTROL:
  107.           goto, tigoto, if ... goto, timout                             16
  108.           reinit, rigoto, rireturn                                      17
  109.      DURATIONAL CONTROL:
  110.           ihold, turnoff                                                    18
  111.      MIDI CONVERTERS:  notnum, veloc, cpsmidi(b), octmidi(b),
  112.           pchmidi(b), ampmidi, aftouch, chpress, pchbend,midictrl          19
  113.      SIGNAL GENERATORS:
  114.           line, expon, linseg, expseg                                   20
  115.           phasor                                                          21
  116.           table, tablei, oscil1, oscil1i                                22
  117.           oscil, oscili, foscil, foscili                                23
  118.           loscil                                                        24
  119.           buzz, gbuzz                                                       25
  120.           adsyn, pvoc                                                       26
  121.           fof                                                               27
  122.           pluck                                                         28
  123.           rand, randh, randi                                                29
  124.      SIGNAL MODIFIERS:
  125.           linen, linenr, envlpx                                         30
  126.           port, tone, atone, reson, areson                              31
  127.           lpread, lpreson, lpfreson                                     32
  128.           rms, gain, balance                                                33
  129.           downsamp, upsamp, interp, integ, diff, samphold               34
  130.           delayr, delayw, delay, delay1                                 35
  131.           deltap, deltapi                                               36
  132.           comb, alpass, reverb                                          37
  133.      OPERATIONS WITH SPECTRAL DATA TYPES:
  134.           octdown, noctdft, specscal, specaddm,
  135.           specdiff, specaccm, specfilt, specdisp, specsum               38
  136.      SENSING & CONTROL:
  137.           tempest                                                           40
  138.           xyin, tempo                                                       41
  139.      SOUNDFILE INPUT & OUTPUT:
  140.           in, ins, insq, soundin, out, outs, outq                       42
  141.           pan                                                               43
  142.      SIGNAL DISPLAY:  print, display, dispfft                           44
  143.  
  144. 3.  STANDARD NUMERIC SCORE                             
  145.      Preprocessing of Standard Scores                                   45
  146.      Next-P and Previous-P Symbols                                      46
  147.      Ramping                                                                47
  148.      Function Table Statement                                           48
  149.      Instrument Note Statements                                         49
  150.      Advance Statement                                                  50
  151.      Tempo Statement                                                    51
  152.      Sections of Score                                                  52
  153.      End of Score                                                       53
  154.  
  155. 4.  GEN ROUTINES                                            
  156.      GEN01                                                                  54
  157.      GEN02                                                                  55
  158.      GEN03                                                                  56
  159.      GEN04                                                                  57
  160.      GEN05, GEN07                                                           58
  161.      GEN06                                                                  59
  162.      GEN08                                                                  60
  163.      GEN09, GEN10, GEN19                                                    61
  164.      GEN11                                                                  62
  165.      GEN12                                                                  63
  166.      GEN13, GEN14                                                           64
  167.      GEN15                                                                  65
  168.      GEN17                                                                 66
  169.  
  170. 5.  SCOT:  A Score Translator
  171.      Orchestra Declaration                                              67
  172.      Score Encoding                                                         68
  173.      Pitch and Rhythm                                                   68
  174.      Groupettes;  Slurs and Ties                                        71
  175.      Macros                                                                 72
  176.      Divisi                                                             73
  177.      Additional Features                                                74
  178.  
  179. 6.  The Unix CSOUND Command                                                    79
  180.      The Extract Feature                                                82
  181.      Independent Preprocessing                                          82
  182.  
  183.  
  184. Appendix 1.  The Soundfile Utility Programs
  185.                intro - directories, paths, and soundfile formats        83
  186.                sndinfo - get basic information about a soundfile        84
  187.                hetro - hetrodyne filter analysis for adsyn              85
  188.                lpanal - lpc analysis for the lp generators              87
  189.                pvanal - fourier analysis for pvoc (Dan Ellis)           88
  190. Appendix 2.  CSCORE: A C-language Score Generator                              89
  191. Appendix 3.  An Instrument Design Tutorial (R.C. Boulanger)                 91
  192. Appendix 4.  An FOF Synthesis Tutorial (J.M. Clarke)                        107
  193. Appendix 5.  Csound for the Macintosh (W. Gardner)                          115
  194. Appendix 6.  Adding your own Cmodules to Csound                             119
  195. Appendix 7.  A CSOUND QUICK REFERENCE                                          122
  196.  
  197. 0. PREFACE
  198.  
  199.  
  200. Realizing music by digital computer involves synthesizing audio
  201. signals with discrete points or samples that are representative
  202. of continuous waveforms.  There are several ways of doing this,
  203. each affording a different manner of control.  Direct synthesis
  204. generates waveforms by sampling a stored function representing a
  205. single cycle;  additive synthesis generates the many partials of
  206. a complex tone, each with its own loudness envelope;  subtractive
  207. synthesis begins with a complex tone and filters it.  Non-linear
  208. synthesis uses frequency modulation and waveshaping to give
  209. simple signals complex characteristics, while sampling and
  210. storage of natural sound allows it to be used at will.
  211.  
  212. Since comprehensive moment-by-moment specification of sound can
  213. be tedious, control is gained in two ways:  1) from the
  214. instruments in an  orchestra, and  2) from the events within a
  215. score.  An orchestra  is really a computer program that can
  216. produce sound, while a score is a body of data which that program
  217. can react to.  Whether a rise-time characteristic is a fixed
  218. constant in an instrument, or a variable of each note in the
  219. score, depends on how the user wants to control it.
  220.  
  221. The instruments in a Csound orchestra are defined in a simple
  222. syntax that invokes complex audio  processing routines.  A score
  223. passed to this orchestra contains numerically coded pitch and
  224. control information, in standard numeric score format.  Although 
  225. many users are content with this format, higher level score
  226. processing languages are often convenient.  
  227.  
  228. The programs making up the Csound system have a long history of
  229. development, beginning with the Music 4 program written at Bell
  230. Telephone Laboratories in the early 1960's by Max Mathews.  That
  231. initiated the stored table concept and much of the terminology
  232. that has since enabled computer music researchers to communicate. 
  233. Valuable additions were made at Princeton by the late Godfrey
  234. Winham in Music 4B;  my own Music 360 (1968) was very indebted to
  235. his work.  With Music 11 (1973) I took a different tack: the two
  236. distinct networks of control and audio signal processing stemmed
  237. from my intensive involvement in the preceding years in hardware
  238. synthesizer concepts and design.  This division has been retained
  239. in Csound.  
  240.  
  241. Because it is written entirely in C, Csound is easily installed
  242. on any machine running Unix or  C.  At MIT it runs on
  243. VAX/DECstations under Ultrix 4.2, on SUNs under OS 4.1, SGIs
  244. under 4.1, and on the Macintosh under ThinkC 4.0.  With this
  245. single language for audio signal processing, users move easily
  246. from machine to machine.
  247.  
  248. The 1991 version included many new features.  I am indebted to
  249. others for the contribution of the phase vocoder and FOF
  250. synthesis modules.  That release also charted a new direction
  251. with the addition of a spectral data type, holding much promise
  252. for future development.  The 1992 release is even more
  253. significant for its addition of MIDI converter and control units,
  254. enabling Csound to be run from MIDI score-files and from external
  255. MIDI keyboards.  Since the newest RISC processors bring to
  256. computer music an order of magnitude more speed than did those on
  257. which it was born, researchers and composers now have access to
  258. workstations on which realtime software synthesis with sensing
  259. and control is now a reality.  This is perhaps the single most
  260. important development for people working in the field.  This new
  261. Csound is designed to take maximum advantage of realtime audio
  262. processing, and to encourage interactive experiments in this
  263. exciting new domain.
  264.  
  265.                                                              B.V. 
  266.  
  267. 1.  A BEGINNING TUTORIAL
  268.  
  269. Introduction
  270.  
  271. The purpose of this section is to expose the reader to the
  272. fundamentals of designing and using computer music instruments in
  273. Csound.  Only a small portion of the language will be covered
  274. here, sufficient to implement some simple instrument examples. 
  275. The sections in this primary text are arranged as a Reference
  276. manual (not a tutorial), since that is the form the user will
  277. eventually find most helpful when inventing instruments.  Once
  278. the basic concepts are grasped from this beginning tutorial, the
  279. reader might let himself into the remainder of the text by
  280. locating the information presented here in the Reference entries
  281. that follow.  More comprehensive tutorials are supplied as
  282. Appendices.
  283.  
  284. The Orchestra File
  285.  
  286. Csound runs from two basic files:  an orchestra file and a score
  287. file.  The orchestra file is a set of instruments that tell the
  288. computer how to synthesize sound;  the score file tells the
  289. computer when.  An instrument is a collection of modular
  290. statements which either generate or modify a signal;  signals are
  291. represented by symbols, which can be "patched" from one module to
  292. another.  For example, the following two statements will generate
  293. a 440 Hz sine tone and send it to an output channel:
  294.  
  295.      asig oscil     10000, 440, 1
  296.           out  asig
  297.  
  298. The first line sets up an oscillator whose controlling inputs are
  299. an amplitude of 10000, a frequency of 440 Hz, and a waveform
  300. number, and whose output is the audio signal asig.  The second
  301. line takes the signal asig and sends it to an (implicit) output
  302. channel.  The two may be encased in another pair of statements
  303. that identify the  instrument as a whole:
  304.  
  305.           instr     1
  306.      asig oscil     10000, 440, 1
  307.           out  asig
  308.           endin
  309.  
  310. In general, an orchestra statement in Csound consists of an
  311. action symbol followed by a set of input variables and preceded
  312. by a result symbol.  Its action is to process the inputs and
  313. deposit the result where told.  The meaning of the input
  314. variables depends on the action requested.  The 10000 above is
  315. interpreted as an amplitude value because it occupies the first
  316. input slot of an oscil unit;  440 signifies a frequency in Hertz
  317. because that is how an oscil unit interprets its second input
  318. argument; the waveform number is taken to point indirectly to a
  319. stored function table, and before we invoke this instrument in a
  320. score we must fill function table #1 with some waveform.
  321.  
  322. The output of Csound computation is not a real audio signal, but
  323. a stream of numbers which describe such a signal.  When written
  324. onto a sound file these can later be converted to sound by an
  325. independent program; for now, we will think of variables such as
  326. asig as tangible audio signals.  
  327.  
  328. Let us now add some extra features to this instrument.  First, we
  329. will allow the pitch of the tone to be defined as a parameter in
  330. the score.  Score parameters can be represented by orchestra
  331. variables which take on their different values on successive
  332. notes.  These variables are named sequentially: p1, p2, p3, ... 
  333. The first three have a fixed meaning (see the Score File), while
  334. the remainder are assignable by the user.  Those of significance
  335. here are:
  336.  
  337.      p3 - duration of the current note (always in seconds).
  338.      p5 - pitch of the current note (in units agreed upon by
  339. score and orchestra).
  340.  
  341. Thus in
  342.  
  343.      asig oscil     10000, p5, 1
  344.  
  345. the oscillator will take its pitch (presumably in cps) from score
  346. parameter 5.
  347.  
  348. If the score had forwarded pitch values in units other than
  349. cycles-per-second (Hertz), then these must first be converted. 
  350. One convenient score encoding, for instance, combines pitch class
  351. representation (00 for C, 01 for C#, 02 for D, ... 11 for B) with
  352. octave representation (8. for middle C,  9. for the C above,
  353. etc.) to give pitch values such as 8.00, 9.03, 7.11.  The
  354. expression
  355.  
  356.      cpspch(8.09)
  357.  
  358. will convert the pitch A (above middle C) to its cps equivalent
  359. (440 Hz).  Likewise, the expression
  360.  
  361.      cpspch(p5)
  362.  
  363. will first read a value from p5, then convert it from
  364. octave.pitch-class units to cps.  This expression could be
  365. imbedded in our orchestra statement as
  366.  
  367.      asig oscil     10000, cpspch(p5), 1
  368.  
  369. to give the score-controlled frequency we sought.
  370.  
  371. Next, suppose we want to shape the amplitude of our tone with a
  372. linear rise from 0 to 10000.  This can be done with a new
  373. orchestra statement
  374.  
  375.      amp  line 0, p3, 10000
  376.  
  377. Here, amp will take on values that move from 0 to 10000 over time
  378. p3 (the duration of the note in seconds).  The instrument will
  379. then become
  380.  
  381.           instr     1
  382.      amp  line 0, p3, 10000
  383.      asig oscil     amp, cpspch(p5), 1
  384.           out  asig
  385.           endin
  386.  
  387. The signal amp is not something we would expect to listen to
  388. directly.  It is really a variable whose purpose is to control
  389. the amplitude of the audio oscillator.  Although audio output
  390. requires fine resolution in time for good fidelity, a controlling
  391. signal often does not need that much resolution.  We could use
  392. another kind of signal for this amplitude control
  393.  
  394.      kamp line 0, p3, 10000
  395.  
  396. in which the result is a new kind of signal.  Signal names up to
  397. this point have always begun with the letter  a  (signifying an
  398. audio signal);  this one begins with  k  (for control).  Control
  399. signals are identical to audio signals, differing only in their
  400. resolution in time.  A control signal changes its value less
  401. often than an audio signal, and is thus faster to generate. 
  402. Using one of these, our instrument would then become 
  403.  
  404.           instr     1
  405.      kamp line 0, p3, 10000
  406.      asig oscil     kamp, cpspch(p5), 1
  407.           out  asig
  408.           endin
  409.  
  410. This would likely be indistinguishable in sound from the first
  411. version, but would run a little faster.  In general, instruments
  412. take constants and parameter values, and use calculations and
  413. signal processing to move first towards the generation of control
  414. signals, then finally audio signals.  Remembering this flow will
  415. help you write efficient instruments with faster execution times.
  416.  
  417. We are now ready to create our first orchestra file.  Type in the
  418. following orchestra using the system editor, and name it
  419. "intro.orc".
  420.  
  421.           sr = 20000               ; audio sampling rate is 20
  422. kHz
  423.           kr = 500                       ; control rate is 500 Hz
  424.           ksmps = 40               ; number of samples in a
  425. control period (sr/kr)
  426.           nchnls = 1               ; number of channels of audio
  427. output
  428.  
  429.           instr     1
  430.      kctrl     line 0, p3, 10000        ; amplitude envelope
  431.      asig oscil     kctrl, cpspch(p5), 1     ; audio oscillator
  432.           out  asig           ; send signal to channel 1
  433.           endin
  434.  
  435. It is seen that comments may follow a semi-colon, and extend to
  436. the end of a line.  There can also be blank lines, or lines with
  437. just a comment.  Once you have saved your orchestra file on disk,
  438. we can next consider the score file that will drive it.
  439.  
  440. The Score File
  441.  
  442. The purpose of the score is to tell the instruments when to play
  443. and with what parameter values.  The score has a different syntax
  444. from that of the orchestra, but similarly permits one statement
  445. per line and comments after a semicolon.  The first character of
  446. a score statement is an opcode, determining an action request;
  447. the remaining data consists of numeric parameter fields (pfields)
  448. to be used by that action.
  449.  
  450. Suppose we want a sine-tone generator to play a pentatonic scale
  451. starting at C-sharp above middle-C, with notes of 1/2 second
  452. duration.  We would create the following score:
  453.  
  454.      ;  a sine wave function table
  455.      f1 0 256 10 1
  456.      ;  a pentatonic scale
  457.      i1    0   .5   0.   8.01
  458.      i1   .5   .    .    8.03
  459.      i1 1.0    .    .    8.06
  460.      i1 1.5    .    .    8.08
  461.      i1 2.0    .    .    8.10
  462.      e
  463.  
  464. The first statement creates a stored sine table.  The protocol
  465. for generating wave tables is simple but powerful.  Lines with
  466. opcode f interpret their parameter fields as follows:
  467.  
  468.      p1 - function table number being created
  469.      p2 - creation time, or time at which the table becomes readable
  470.      p3 - table size (number of points), which must be a power of
  471.         two or one greater
  472.      p4 - generating subroutine, chosen from a prescribed list.
  473.  
  474. Here the value 10 in p4 indicates a request for subroutine GEN10
  475. to fill the table.  GEN10 mixes harmonic sinusoids in phase, with
  476. relative strengths of consecutive partials given by the
  477. succeeding parameter fields.  Our score requests just a single
  478. sinusoid.  An alternative statement:
  479.  
  480.      f1 0 256 10 1 0 3
  481.  
  482. would produce one cycle of a waveform with a third harmonic three
  483. times as strong as the first.
  484.  
  485. The i statements, or note statements, will invoke the p1
  486. instrument at time p2, then turn it off after p3 seconds; it will
  487. pass all of its p-fields to that instrument.  Individual score
  488. parameters are separated by any number of spaces or tabs; neat
  489. formatting of parameters in columns is nice but unnecessary.  The
  490. dots in p-fields 3 and 4 of the last four notes invoke a carry
  491. feature, in which values are simply copied from the immediately
  492. preceding note of the same instrument.  A score normally ends
  493. with an e statement.
  494.  
  495. The unit of time in a Csound score is the beat.  In the absence
  496. of a Tempo statement, one beat takes one second.  To double the
  497. speed of the pentatonic scale in the above score, we could either
  498. modify p2 and p3 for all the notes in the score, or simply insert
  499. the line
  500.  
  501.      t 0 120
  502.  
  503. to specify a tempo of 120 beats per minute from beat 0.
  504.  
  505. Two more points should be noted.  First, neither the f-statements
  506. nor the i-statements need be typed in time order; Csound will
  507. sort the score automatically before use.  Second, it is
  508. permissible to play more than one note at a time with a single
  509. instrument.  To play the same notes as a three-second pentatonic
  510. chord we would create the following:
  511.  
  512.      ;    a sine wave function
  513.      f1 0 256 10 1
  514.      ;    five notes at once
  515.      i1   0    3    0    8.01
  516.      i1   0    .    .    8.03
  517.      i1   0    .    .    8.06
  518.      i1   0    .    .    8.08
  519.      i1   0    .    .    8.10
  520.      e
  521.  
  522. Now go into the editor once more and create your own score file. 
  523. Name it "intro.sco".  Tne next section will describe how to
  524. invoke a Csound orchestra to perform a Csound score.
  525.  
  526.  
  527. The CSOUND Command
  528.  
  529. To request your orchestra to perform your score, type the command
  530.  
  531.      csound  intro.orc  intro.sco
  532.  
  533. The resulting performance will take place in three phases:
  534.  
  535.      1)  sort the score file into chronological order.  If score
  536. syntax errors are encountered they will be reported on your
  537. console.
  538.  
  539.      2)  translate and load your orchestra.  The console will
  540. signal the start of translating each instr block, and will report
  541. any errors.  If the error messages are not immediately
  542. meaningful, translate again with the verbose flag turned on:
  543.  
  544.      csound  -v  intro.orc  intro.sco
  545.  
  546.      3)  fill the wave tables and perform the score.  Information
  547. about this performance will be displayed throughout in messages
  548. resembling
  549.  
  550.      B  4.000 .. 6.000   T 3.000  TT  3.000  M    7929.    7929.
  551.  
  552. A message of this form will appear for every event in your score. 
  553. An event is defined as any change of state (as when a new note
  554. begins or an old one ends).  The first two numbers refer to beats
  555. in your original score, and they delimit the current segment of
  556. sound synthesis between successive events (e.g.  from beat 4 to
  557. beat 6).  The second beat value is next restated in real seconds
  558. of time, and reflects the tempo of the score.  That is followed
  559. by the Total Time elapsed for all sections of the score so far. 
  560. The last values on the line show the maximum amplitude of the
  561. audio signal, measured over just this segment of time, and
  562. reported separately for each channel.
  563.  
  564. Console messages are printed to assist you in following the
  565. orchestra's handling of your score.  You should aim at becoming
  566. an intelligent reader of your console reports.  When you begin
  567. working with longer scores and your instruments no longer cause
  568. surprises, the above detail may be excessive.  You can elect to
  569. receive abbreviated messages using the -m option of the Csound
  570. command.
  571.  
  572. When your performance goes to completion, it will have created a
  573. sound file named test in your soundfile directory.  You can now
  574. listen to your sound file by typing
  575.  
  576.      play test
  577.  
  578. If your machine is fast enough, and your Csound module includes
  579. user access to the audio output device, you can hear your sound
  580. as it is being synthesized by using a command like
  581.  
  582.      csound  -o  devaudio  intro.orc  intro.sco
  583.  
  584. More about the Orchestra
  585.  
  586. Suppose we next wished to introduce a small vibrato, whose rate
  587. is 1/50 the frequency of the note (i.e.  A440 is to have a
  588. vibrato rate of 8.8 Hz.).  To do this we will generate a control
  589. signal using a second oscillator, then add this signal to the
  590. basic frequency derived from p5.  This might result in the
  591. instrument
  592.  
  593.           instr     1
  594.      kamp line      0, p3, 10000
  595.      kvib oscil     2.75, cpspch(p5)/50, 1
  596.      a1   oscil     kamp, cpspch(p5)+kvib, 1
  597.           out       a1
  598.           endin
  599.  
  600. Here there are two control signals, one controlling the amplitude
  601. and the other modifying the basic pitch of the audio oscillator. 
  602. For small vibratos, this instrument is quite practical;  however
  603. it does contain a misconception worth noting.  This scheme has
  604. added a sine wave deviation to the cps value of an audio
  605. oscillator.  The value 2.75 determines the width of vibrato in
  606. cps, and will cause an A440 to be modified about one-tenth of one
  607. semitone in each direction (1/160 of the frequency in cps).  In
  608. reality, a cps deviation produces a different musical interval
  609. above than it does below.  To see this, consider an exaggerated
  610. deviation of 220 cps, which would extend a perfect 5th above A440
  611. but a whole octave below.  To be more correct, we should first
  612. convert p5 into a true decimal octave (not cps), so that an
  613. interval deviation above is equivalent to that below.  In
  614. general, pitch modification is best done in true octave units
  615. rather than pitch-class or cps units, and there exists a group of
  616. pitch converters to make this task easier.  The modified
  617. instrument would be
  618.  
  619.           instr     1
  620.      ioct =         octpch(p5)
  621.      kamp line      0, p3, 10000
  622.      kvib oscil     1/120, cpspch(p5)/50, 1
  623.      asig oscil     kamp, cpsoct(ioct+kvib), 1
  624.           out       asig
  625.           endin
  626.  
  627. This instrument is seen to use a third type of orchestra
  628. variable, an i-variable.  The variable ioct receives its value at
  629. an initialization pass through the instrument, and does not
  630. change during the lifespan of this note.  There may be many such
  631. init time calculations in an instrument.  As each note in a score
  632. is encountered, the event space is allocated and the instrument
  633. is initialized by a special pre-performance pass.  i-variables
  634. receive their values at this time, and any other expressions
  635. involving just constants and i-variables are evaluated.  At this
  636. time also, modules such as line will set up their target values
  637. (such as beginning and end points of the line), and units such as
  638. oscil will do phase setup and other bookkeeping in preparation
  639. for performance.  A full description of init-time and
  640. performance-time activities, however, must be deferred to a
  641. general consideration of the orchestra syntax.
  642. 2.  SYNTAX OF THE ORCHESTRA
  643.  
  644.  
  645. An orchestra statement in Csound has the format:
  646.  
  647.      label:   result    opcode    argument1, argument2, ... ; comments
  648.  
  649. The label is optional and identifies the basic statement that
  650. follows as the potential target of a go-to operation (see Program
  651. Control Statements).  A label has no effect on the statement per
  652. se.
  653.  
  654. Comments are optional and are for the purpose of letting the user
  655. document his orchestra code.  Comments always begin with a
  656. semicolon (;) and extend to the end of the line.
  657.  
  658. The remainder (result, opcode, and arguments) form the basic
  659. statement.  This also is optional, i.e.  a line may have only a
  660. label or comment or be entirely blank.  If present, the basic
  661. statement must be complete on one line.  The opcode determines
  662. the operation to be performed;  it usually takes some number of
  663. input values (arguments); and it usually has a result field
  664. variable to which it sends output values at some fixed rate. 
  665. There are four possible rates:
  666.  
  667.      1) once only, at orchestra setup time (effectively a
  668. permanent assignment);
  669.      2) once at the beginning of each note (at initialization
  670. (init) time:  I-rate);
  671.      3) once every performance-time control loop (perf time
  672. control rate, or  K-rate);
  673.      4) once each sound sample of every control loop (perf time
  674. audio rate, or  A-rate).
  675.  
  676. ORCHESTRA STATEMENT TYPES
  677.  
  678. An orchestra program in Csound is comprised of orchestra header
  679. statements which set various global parameters, followed by a
  680. number of instrument blocks representing different instrument
  681. types.  An instrument block, in turn, is comprised of ordinary
  682. statements that set values, control the logical flow, or invoke
  683. the various signal processing subroutines that lead to audio
  684. output.
  685.  
  686. An orchestra header statement operates once only, at orchestra
  687. setup time.  It is most commonly an assignment of some value to a
  688. global reserved symbol, e.g.  sr = 20000.  All orchestra header
  689. statements belong to a pseudo instrument 0, an init pass of which
  690. is run prior to all other instruments at score time 0.  Any
  691. ordinary statement can serve as an orchestra header statement,
  692. eg.  gifreq = cpspch(8.09), provided it is an init-time only
  693. operation.
  694.  
  695. An ordinary statement runs at either init time or performance
  696. time or both.  Operations which produce a result formally run at
  697. the rate of that result (that is, at init time for I-rate
  698. results; at performance time for K- and A-rate results), with the
  699. sole exception of the init opcode (q.v.).  Most generators and
  700. modifiers, however, produce signals that depend not only on the
  701. instantaneous value of their arguments but also on some preserved
  702. internal state.  These performance-time units therefore have an
  703. implicit init-time component to set up that state.  The run time
  704. of an operation which produces no result is apparent in the
  705. opcode.
  706.  
  707. Arguments are values that are sent to an operation.  Most
  708. arguments will accept arithmetic expressions composed of
  709. constants, variables, reserved globals, value converters,
  710. arithmetic operations and conditional values; these are described
  711. below.
  712.  
  713. CONSTANTS AND VARIABLES
  714.  
  715. constants are floating point numbers, such as 1, 3.14159, or
  716. -73.45.  They are available continuously and do not change in
  717. value.
  718.  
  719. variables are named cells containing numbers.  They are available
  720. continuously and may be updated at one of the four update rates
  721. (setup only, I-rate, K-rate, or A-rate).  I- and K-rate variables
  722. are scalars (i.e.  they take on only one value at any given time)
  723. and are primarily used to store and recall controlling data, that
  724. is, data that changes at the note rate (for I-variables) or at
  725. the control rate (for K-variables).  I- and K-variables are
  726. therefore useful for storing note parameter values, pitches,
  727. durations, slow-moving frequencies, vibratos, etc.  A-variables,
  728. on the other hand, are arrays or vectors of information.  Though
  729. renewed on the same perf-time control pass as K-variables, these
  730. array cells represent a finer resolution of time by dividing the
  731. control period into sample periods (see ksmps below). 
  732. A-variables are used to store and recall data changing at the
  733. audio sampling rate (e.g.  output signals of oscillators,
  734. filters, etc.).
  735.  
  736. A further distinction is that between local and global variables. 
  737. local variables are private to a particular instrument, and
  738. cannot be read from or written into by any other instrument. 
  739. Their values are preserved, and they may carry information from
  740. pass to pass (e.g.  from initialization time to performance time)
  741. within a single instrument.  Local variable names begin with the
  742. letter p, i, k, or a.  The same local variable name may appear in
  743. two or more different instrument blocks without conflict.
  744.  
  745. global variables are cells that are accessible by all
  746. instruments.  The names are either like local names preceded by
  747. the letter g, or are special reserved symbols.  Global variables
  748. are used for broadcasting general values, for communicating
  749. between instruments (semaphores), or for sending sound from one
  750. instrument to another (e.g. mixing prior to reverberation).  
  751.  
  752. Given these distinctions, there are eight forms of local and
  753. global variables:
  754.  
  755.      type           when renewable      Local     Global
  756.  
  757. reserved symbols         permanent      --        rsymbol
  758. score parameter fields   I-time         pnumber   --
  759. init variables           I-time         iname     giname
  760. control signals          P-time, K-rate kname     gkname
  761. audio signals            P-time, A-rate aname     ganame
  762.  
  763. where rsymbol is a special reserved symbol (e.g.  sr, kr), number
  764. is a positive integer referring to a score statement pfield, and
  765. name is a string of letters and/or digits with local or global
  766. meaning.  As might be inferred, score parameters are local
  767. I-variables whose values are copied from the invoking score
  768. statement just prior to the Init pass through an instrument.
  769.  
  770. VALUE CONVERTERS
  771.  
  772.           ftlen(x)       (init-rate args only)
  773.  
  774.           int(x)         (init- or control-rate args only)
  775.           frac(x)        (init- or control-rate args only)
  776.           dbamp(x)       (init- or control-rate args only)
  777.  
  778.           i(x)           (control-rate args only)
  779.  
  780.           abs(x)         (no rate restriction)
  781.           exp(x)         (no rate restriction)
  782.           log(x)         (no rate restriction)
  783.           sqrt(x)        (no rate restriction)
  784.           sin(x)         (no rate restriction)
  785.           cos(x)         (no rate restriction)
  786.           ampdb(x)       (no rate restriction)
  787.  
  788. where the argument within the parentheses may be an expression.
  789.  
  790. Value converters perform arithmetic translation from units of one
  791. kind to units of another.  The result can then be a term in a
  792. further expression.
  793.  
  794. ftlen(x)  returns the size (no.  of points) of stored function
  795.           table no.  x.
  796.  
  797. int(x)    returns the integer part of x.
  798.  
  799. frac(x)   returns the fractional part of x.
  800.  
  801. dbamp(x)  returns the decibel equivalent of the raw amplitude x.
  802.  
  803. i(x)      returns an Init-type equivalent of the argument, thus
  804.           permitting a K-time value to be accessed in at init-time or 
  805.           reinit-time, whenever valid.
  806.  
  807. abs(x)    returns the absolute value of x.
  808.  
  809. exp(x)    returns e  raised to the xth power.
  810.  
  811. log(x)    returns the natural log of x (x positive only).
  812.  
  813. sqrt(x)   returns the square root of x  (x non-negative).
  814.  
  815. sin(x)    returns the sine of x (x in radians).
  816.  
  817. cos(x)    returns the cosine of x (x in radians).
  818.  
  819. ampdb(x)  returns the amplitude equivalent of the decibel value x.
  820.           Thus 60 db gives 1000, 66 db gives 2000, 72 db gives 4000,
  821.           78 db gives 8000, 84 db gives 16000 and 90 db gives 32000.
  822.  
  823. Note that for log, sqrt, and ftlen the argument value is
  824. restricted.  Note also that ftlen will always return a power-of-2
  825. value, i.e. the function table guard point (see F statement) is
  826. not included.
  827.  
  828. PITCH CONVERTERS 
  829.  
  830.           octpch(pch)         (init- or control-rate args only) 
  831.           pchoct(oct)         (init- or control-rate args only) 
  832.           cpspch(pch)         (init- or control-rate args only) 
  833.           octcps(cps)         (init- or control-rate args only) 
  834.           cpsoct(oct)         (no rate restriction) 
  835.  
  836. where the argument within the parentheses may be a further
  837. expression.  
  838.  
  839. These are really value converters with a special function of
  840. manipulating pitch data.  
  841.  
  842. Data concerning pitch and frequency can exist in any of the
  843. following forms: 
  844.  
  845.      name                     abbreviation 
  846.  
  847.      octave point pitch-class (8ve.pc)  pch
  848.      octave point decimal               oct 
  849.      cycles per second                  cps
  850.  
  851. The first two forms consist of a whole number, representing
  852. octave registration, followed by a specially interpreted
  853. fractional part.  For pch, the fraction is read as two decimal
  854. digits representing the 12 equal-tempered pitch classes from .00
  855. for C to.11 for B.  For oct, the fraction is interpreted as a
  856. true decimal fractional part of an octave.  The two fractional
  857. forms are thus related by the factor 100/12.  In both forms, the
  858. fraction is preceded by a whole number octave index such that
  859. 8.00 represents Middle C,9.00 the C above, etc.  Thus A440 can be
  860. represented alternatively by 440 (cps),8.09 (pch), 8.75 (oct), or
  861. 7.21 (pch), etc.  Microtonal divisions of the pch semitone can be
  862. encoded by using more than two decimal places.  
  863.  
  864. The mnemonics of the pitch conversion units are derived from
  865. morphemes of the forms involved, the second morpheme describing
  866. the source and the first morpheme the object (result).  Thus 
  867.  
  868.                cpspch(8.09) 
  869.  
  870. will convert the pitch argument 8.09 to its cps (or Hertz)
  871. equivalent, giving the value of 440.  Since the argument is
  872. constant over the duration of the note, this conversion will take
  873. place at I-time, before any samples for the current note are
  874. produced.  By contrast, the conversion 
  875.  
  876.                cpsoct(8.75 + K1) 
  877.  
  878. which gives the value of A440 transposed by the octave interval
  879. K1 will repeat the calculation every, K-period since that is the
  880. rate at which K1 varies.  
  881.  
  882. N.B. The conversion from pch or oct into cps is not a linear
  883. operation but involves an exponential process that could be
  884. time-consuming when executed repeatedly.  Csound now uses a
  885. built-in table lookup to do this efficiently, even at audio
  886. rates. 
  887.  
  888. ARITHMETIC OPERATIONS: 
  889.                     - a
  890.                     + a 
  891.                     a  && b        (logical AND;  not audio-rate) 
  892.                     a  || b        (logical OR;   not audio-rate) 
  893.                     a  +  b
  894.                     a  -  b 
  895.                     a  *  b 
  896.                     a  /  b
  897.  
  898. where the arguments a and b may be further expressions.  
  899.  
  900. Arithmetic operators perform operations of change-sign (negate),
  901. don't-change-sign, logical AND logical OR, add, subtract,
  902. multiply and divide.  Note that a value or an expression may fall
  903. between two of these operators, either of which could take it as
  904. its left or right argument, as in 
  905.                     a + b * c.  
  906.  
  907. In such cases three rules apply: 
  908.      1) * and / bind to their neighbors more strongly than + and -.  
  909.           Thus the above expression is taken as 
  910.                     a + (b * c), 
  911.           with * taking b and c and then + taking a and b * c.  
  912.      2) + and - bind more strongly than &&, which in turn is stronger than ||:
  913.                a && b - c || d is taken as (a && (b-c)) || d 
  914.      3) When both operators bind equally strongly, 
  915.           the operations are done left to right: 
  916.                a - b - c is taken as (a - b) - c.  
  917.  
  918. Parentheses may be used as above to force particular groupings.  
  919.  
  920. CONDITIONAL VALUES: 
  921.                     (a > b    ?  v1 : v2) 
  922.                     (a < b    ?  v1 : v2) 
  923.                     (a  > = b   ?  v1 : v2) 
  924.                     (a  < = b   ?  v1 : v2) 
  925.                     (a  = = b   ?  v1 : v2) 
  926.                     (a  ! = b   ?  v1 : v2) 
  927.  
  928. where a, b, v1 and v2 may be expressions, but a, b not
  929. audio-rate.
  930.  
  931. In the above conditionals, a and b are first compared.  If the
  932. indicated relation is true (a  greater than b, a less than b, a
  933. greater than or equal to b, a less than or equal to b, a equal to
  934. b, a not equal to b), then the conditional expression has the
  935. value of v1; if the relation is false, the expression has the
  936. value of v2.  (For convenience, a sole `=` will function as `=
  937. =`.) NB.: If v1 or v2 are expressions, these will be evaluated
  938. before the conditional is determined.
  939.  
  940. In terms of binding strength, all conditional operators (i.  e.,
  941. the relational operators (>,<, etc.), and ?, and : ) are weaker
  942. than the arithmetic and logical operators (+, -, *, /, && and ||).
  943.  
  944. Example: 
  945.                (k1 < p5/2 + p6 ? k1 : p7) 
  946.  
  947. binds the terms p5/2 and p6.  It will return the value k1 below
  948. this threshold, else the value p7.  
  949.  
  950. EXPRESSIONS: 
  951.  
  952. Expressions may be composed to any depth from the components
  953. shown above.  Each part of an expression is evaluated at its own
  954. proper rate.  For instance, if the terms within a sub-expression
  955. all change at the control rate or slower, the sub-expression will
  956. be evaluated only at the control rate; that result might then be
  957. used in an audio-rate evaluation.  For example, in
  958.                k1 + abs(int(p5) + frac(p5) * 100/12 +  sqrt(k1)) 
  959. the 100/12 would be evaluated at orch init, the p5 expressions
  960. evaluated at note I-time, and the remainder of the expression
  961. evaluated every k-period.  The whole might occur in a unit
  962. generator argument position, or be part of an assignment
  963. statement .
  964.  
  965. DIRECTORIES and FILES:
  966.  
  967. Many generators and the csound command itself specify filenames
  968. to be read from or written to.  These are optionally full
  969. pathnames, whose target directory is fully specified.  When not
  970. fullpath, filenames are sought in several directories in order,
  971. depending on their type and on the setting of certain environment
  972. variables.  The latter are optional, but they can serve to
  973. partition and organize the directories so that source files can
  974. be shared rather than duplicated in several user directories. 
  975. The environment variables can define directories for soundfiles
  976. (SFDIR), sound samples (SSDIR), and sound analysis (SADIR).  The
  977. search order is:  
  978.  
  979.      Soundfiles being written are placed in SFDIR (if it exists),
  980. else the current directory.
  981.      Soundfiles for reading are sought in the current directory,
  982. then SSDIR, then SFDIR.
  983.      Analysis control files for reading are sought in the current
  984. directory, then SADIR.
  985.  
  986. NOMENCLATURE: 
  987.  
  988. In Csound there are nine statement types, each of which provides
  989. a heading for the descriptive sections that follow in this
  990. chapter: 
  991.  
  992.      assignment statements              signal generator statements 
  993.      orchestra header statements        signal modifier statements 
  994.      instrument block statements        ignal display statements 
  995.      program control statements         soundfile access statements 
  996.      duration control statements             
  997.      
  998. Throughout this document, opcodes are indicated in boldface and
  999. their argument and result mnemonics, when mentioned in the text,
  1000. are given in italics.  Argument names are generally mnemonic
  1001. (amp, phs), and the result is denoted the letter r.  Both are
  1002. preceded by a type qualifier i, k, a or x (e.g.  kamp, iphs, ar). 
  1003. The prefix i denotes scalar values valid at note Init time;
  1004. prefixes k or a denote control (scalar) and audio (vector)
  1005. values, modified and referenced continuously throughout
  1006. performance (i.e.  at every control period while the instrument
  1007. is active).  Arguments are used at the prefix-listed times;
  1008. results are created at their listed times, then remain available
  1009. for use as inputs elsewhere.  The validity of inputs is defined
  1010. by the following: 
  1011.  
  1012.      arguments with prefix i must be valid at Init time; 
  1013.      arguments with prefix k can be either control or Init values
  1014. (which remain valid); 
  1015.      arguments with prefix a must be vector inputs; 
  1016.      arguments with prefix x may be either vector or scalar (the
  1017. compiler will distinguish).
  1018.  
  1019. All arguments, unless otherwise stated, can be expressions whose
  1020. results conform to the above.  Most opcodes (such as linen and
  1021. oscil) can be used in more than one mode, which one being
  1022. determined by the prefix of the result symbol.
  1023.  
  1024. ASSIGNMENT STATEMENTS 
  1025.  
  1026.      ir   =    iarg
  1027.      kr   =    karg
  1028.      ar   =    xarg
  1029.      kr   init iarg
  1030.      ar   init iarg
  1031.  
  1032.      ir   tival
  1033.  
  1034.      ir   divz ia, ib, isubst   (these not yet implemented)
  1035.      kr   divz ka, kb, ksubst
  1036.      ar   divz xa, xb, ksubst
  1037.  
  1038. = (simple assignment) - Put the value of the expression iarg
  1039. (karg, xarg) into the named result.  This provides a means of
  1040. saving an evaluated result for later use.  
  1041.  
  1042. init - Put the value of the I-time expression iarg into a K- or
  1043. A-variable, i.e., initialize the result.  Note that init provides
  1044. the only case of an Init-time statement being permitted to write
  1045. into a Perftime (K- or A-rate) result cell; the statement has no
  1046. effect at Perf-time.  
  1047.  
  1048. tival - Put the value of the instrument's internal "tie-in" flag
  1049. into the named I-variable.  Assigns 1 if this note has been
  1050. 'tied' onto a previously held note (see I Statement); assigns 0
  1051. if no tie actually took place.  (See also tigoto.) 
  1052.  
  1053. divz  - Whenever b is not zero, set the result to the value a /
  1054. b; when b is zero, set it to the value of subst instead.  
  1055.  
  1056.  
  1057.  
  1058. Example: 
  1059.  
  1060.      kcps   =  i2/3 + cpsoct(k2 + octpch(p5)) 
  1061.  
  1062. ORCHESTRA HEADER STATEMENTS 
  1063.  
  1064.           sr = n1
  1065.           kr = n2
  1066.           ksmps = n3 
  1067.           nchnls = n4 
  1068.  
  1069. These statements are global value assignments, made at the
  1070. beginning of an orchestra, before any instrument block is
  1071. defined.  Their function is to set certain reserved symbol
  1072. variables that are required for performance.  Once set, these
  1073. reserved symbols can be used in expressions anywhere in the
  1074. orchestra.  
  1075.  
  1076. sr = (optional) - set sampling rate to n1 samples per second per
  1077. channel.  The default value is 10000.  
  1078.  
  1079. kr = (optional) - set control rate to n2 samples per second.  The
  1080. default value is 1000.  
  1081.  
  1082. ksmps = (optional) - set the number of samples in a Control
  1083. Period to n3.  This value must equal sr/kr.  The default value is
  1084. 10.  
  1085.  
  1086. nchnls = (optional) - set number of channels of audio output to
  1087. n4.  (1 = mono, 2 = stereo, 4 = quadraphonic.) The default value
  1088. is 1 (mono).  
  1089.  
  1090. In addition, any global variable can be initialized by an
  1091. init-time assignment anywhere before the first instr statement.  
  1092.  
  1093.  
  1094.  
  1095. All of the above assignments are run as instrument 0 (i - pass
  1096. only) at the start of real performance.  
  1097.  
  1098.  
  1099.  
  1100. Example of header assignments: 
  1101.  
  1102.      sr = 10000 
  1103.      kr = 500 
  1104.      ksmps = 20 
  1105.  
  1106. gi1  =    sr/2.
  1107. ga   init 0
  1108. gitranspose =  octpch(.0l) 
  1109.  
  1110. INSTRUMENT BLOCK STATEMENTS 
  1111.  
  1112.           instr         i, j, ...
  1113.           .
  1114.           .    < body 
  1115.           .       of 
  1116.           .       instrument >
  1117.           .
  1118.           endin 
  1119.  
  1120. These statements delimit an instrument block.  They must always
  1121. occur in pairs.  
  1122.  
  1123.  
  1124. instr - begin an instrument block defining instruments i, j, ...  
  1125.  
  1126. i, j, ...  must be numbers, not expressions.  Any positive
  1127. integer is legal, and in any order, but excessively high numbers
  1128. are best avoided.  
  1129.  
  1130.  
  1131. endin - end the current instrument block.  
  1132.  
  1133.  
  1134.  
  1135. Note: 
  1136.  
  1137. There may be any number of instrument blocks in an orchestra.  
  1138.  
  1139. Instruments can be defined in any order (but they will always be
  1140. both initialized and performed in ascending instrument number
  1141. order).  
  1142.  
  1143. Instrument blocks cannot be nested (i.e. one block cannot contain
  1144. another).  
  1145.  
  1146. PROGRAM CONTROL STATEMENTS 
  1147.  
  1148.           igoto     label 
  1149.           tigoto    label 
  1150.           kgoto     label 
  1151.           goto      label 
  1152.           if        ia R ib igoto label 
  1153.           if        ka R kb kgoto label 
  1154.           if        ia R ib goto label 
  1155.           timout    istrt, idur, label 
  1156.  
  1157. where label is in the same instrument block and is not an
  1158. expression, and where R is one of the Relational operators (>, <,
  1159. >=, <=, ==, !=) (and = for convenience, see also under
  1160. Conditional values).  
  1161.  
  1162. These statements are used to control the order in which
  1163. statements in an instrument block are to be executed.  I-time and
  1164. P-time passes can be controlled separately as follows: 
  1165.  
  1166.  
  1167. igoto - During the I-time pass only, unconditionally transfer
  1168. control to the statement labeled by label.  
  1169.  
  1170. tigoto - similar to igoto, but effective only during an I-time
  1171. pass at which a new note is being 'tied' onto a previously held
  1172. note (see I Statement); no-op when a tie has not taken place. 
  1173. Allows an instrument to skip initialization of units according to
  1174. whether a proposed tie was in fact successful (see also tival,
  1175. delay).  
  1176.  
  1177. kgoto - During the P-time passes only, unconditionally transfer
  1178. control to the statement labeled by label.  
  1179.  
  1180. goto - (combination of igoto and kgoto) Transfer control to label
  1181. on every pass.  
  1182.  
  1183. if...igoto - conditional branch at I-time, depending on the truth
  1184. value of the logical expression "ia R ib".  The branch is taken
  1185. only if the result is true.  
  1186.  
  1187. if...kgoto - conditional branch during P-time, depending on the
  1188. truth value of the logical expression "ka R kb".  The branch is
  1189. taken only if the result is true.  
  1190.  
  1191. if...goto - combination of the above.  Condition tested on every
  1192. pass.  
  1193.  
  1194. timout - conditional branch during P-time, depending on elapsed
  1195. note time.  istrt and idur specify time in seconds.  The branch
  1196. to label will become effective at time istrt, and will remain so
  1197. for just idur seconds.  Note that timout can be reinitialized for
  1198. multiple activation within a single note (see example next page). 
  1199.  
  1200.  
  1201.  
  1202. Example: 
  1203.  
  1204.      if k3 > p5 + 10 kgoto next 
  1205.  
  1206.           reinit     label 
  1207.           rigoto     label 
  1208.           rireturn
  1209.  
  1210. These statements permit an instrument to reinitialize itself
  1211. during performance.  
  1212.  
  1213.  
  1214. reinit - whenever this statement is encountered during a P-time
  1215. pass, performance is temporarily suspended while a special
  1216. Initialization pass, beginning at label and continuing to
  1217. rireturn or endin, is executed.  Performance will then be resumed
  1218. from where it left off.  
  1219.  
  1220. rigoto - similar to igoto, but effective only during a reinit
  1221. pass (i.e., No-op at standard I-time).  This statement is useful
  1222. for bypassing units that are not to be reinitialized.  
  1223.  
  1224. rireturn - terminates a reinit pass (i.e., No-op at standard
  1225. I-time).  This statement, or an endin, will cause normal
  1226. performance to be resumed.  
  1227.  
  1228.  
  1229. Example: 
  1230.  
  1231. The following statements will generate an exponential control
  1232. signal whose value moves from 440 to 880 exactly ten times over
  1233. the duration p3.  
  1234.  
  1235. reset:    timout         0, p3 /10, contin   ;after p3/10 seconds,
  1236.           reinit         reset               ; reinit both timout
  1237. contin:   expon          440, p3/10,880      ; and expon
  1238.           riretum                            ; then resume perf
  1239.  
  1240. DURATION CONTROL STATEMENTS 
  1241.  
  1242.           ihold
  1243.           turnoff 
  1244.  
  1245. These statements permit the current note to modify its own
  1246. duration.  
  1247.  
  1248.  
  1249. ihold - this I-time statement causes a finite-duration note to
  1250. become a `held' note.  It thus has the same effect as a negative
  1251. p3 (see Score I-statement), except that p3 here remains positive
  1252. and the instrument reclassifies itself to being held
  1253. indefinitely.  The note can be turned off explicitly with
  1254. turnoff, or its space taken over by another note of the same
  1255. instrument number (i.e. it is tied into that note).  Effective at
  1256. I-time only; no-op during a reinit pass.  
  1257.  
  1258. turnoff - this P-time statement enables an instrument to turn
  1259. itself off.  Whether of finite duration or 'held', the note
  1260. currently being performed by this instrument is immediately
  1261. removed from the active note list.  No other notes are affected.  
  1262.  
  1263.  
  1264. Example: 
  1265.  
  1266. The following statements will cause a note to terminate when a
  1267. control signal passes a certain threshold (here the Nyquist
  1268. frequency).  
  1269.  
  1270. k1   expon     440, p3/10,880      ; begin gliss and continue
  1271.      if   k1 < sr/2 kgoto contin   ; until Nyquist detected
  1272.      turnoff                       ; then quit 
  1273. contin:   a1   oscil     a1, k1, 1
  1274.  
  1275. MIDI CONVERTERS 
  1276.  
  1277.      ival notnum
  1278.      ival veloc
  1279.      icps cpsmidi
  1280.      icps cpsmidib
  1281.      kcps cpsmidib
  1282.      ioct octmidi
  1283.      ioct octmidib
  1284.      koct octmidib
  1285.      ipch pchmidi
  1286.      ipch pchmidib
  1287.      kpch pchmidib
  1288.      iamp ampmidi   iscal[, ifn]
  1289.      kaft aftouch   iscal
  1290.      kchpr     chpress   iscal
  1291.      kbend     pchbend   iscal
  1292.      ival midictrl  inum
  1293.      kval midictrl  inum
  1294.  
  1295. Get a value from the MIDI event that activated this instrument,
  1296. or from a continuous MIDI controller, and convert it to a locally
  1297. useful format.
  1298.  
  1299. INITIALIZATION
  1300.  
  1301. iscal - I-time scaling factor.
  1302.  
  1303. ifn  (optional) - function table number of a normalized
  1304. translation table, by which the incoming value is first
  1305. interpreted.  The default value is 0, denoting no translation.
  1306.  
  1307. inum - MIDI controller number.
  1308.  
  1309. PERFORMANCE 
  1310.  
  1311. notnum, veloc - get the MIDI byte value (0 - 127) denoting the
  1312. note number or velocity  of the current event.
  1313.  
  1314. cpsmidi, octmidi, pchmidi - get the note number of the current
  1315. MIDI event, expressed in cps, oct, or pch units for local
  1316. processing.
  1317.  
  1318. cpsmidib, octmidib, pchmidib - get the note number of the current
  1319. MIDI event, modify it by the current pitch-bend value, and
  1320. express the result in cps, oct, or pch units.  Available as an
  1321. I-time value or as a continuous ksig value.
  1322.  
  1323. ampmidi - get the velocity of the current MIDI event, optionally
  1324. pass it through a normalized translation table, and return an
  1325. amplitude value in the range 0 - iscal.
  1326.  
  1327. aftouch, chpress, pchbend - get the current after-touch, channel
  1328. pressure, or pitch-bend value for this channel, rescaled to the
  1329. range 0 - iscal.  Note that this access to pitch-bend data is
  1330. independent of the MIDI pitch, enabling the value here to be used
  1331. for any arbitrary purpose.
  1332.  
  1333. midictrl - get the current value (0 - 127) of a specified MIDI
  1334. controller.
  1335.  
  1336. SIGNAL GENERATORS 
  1337.  
  1338.      kr   line      ia, idur1, ib
  1339.      ar   line      ia, idur1, ib
  1340.      kr   expon     ia, idur1, ib 
  1341.      ar   expon     ia, idur1, ib 
  1342.      kr   linseg    ia, idur1, ib[, idur2, ic[...]] 
  1343.      ar   linseg    ia, idur1, ib[, idur2, icI...]]
  1344.      kr   expseg    ia, idur1, ib[, idur2, ic[...]]
  1345.      ar   expseg    ia, idur1, ib[, idur2, ic[...]]
  1346.  
  1347. Output values kr or ar trace a straight line (exponential curve)
  1348. or a series of line segments (exponential segments) between
  1349. specified points.  
  1350.  
  1351. INITIALIZATION
  1352.  
  1353. ia - starting value.  Zero is illegal for exponentials.  
  1354.  
  1355. ib, ic, etc.  - value after dur1 seconds, etc.  For exponentials,
  1356. must be non-zero and must agree in sign with ia.  
  1357.  
  1358. idur1 - duration in seconds of first segment.  A zero or negative
  1359. value will cause all initialization to be skipped.  
  1360.  
  1361. idur2, idur3, etc.  - duration in seconds of subsequent segments. 
  1362. A zero or negative value will terminate the initialization
  1363. process with the preceding point, permitting the last-defined
  1364. line or curve to be continued indefinitely in performance.  The
  1365. default is zero.  
  1366.  
  1367. PERFORMANCE 
  1368.  
  1369. These units generate control or audio signals whose values can
  1370. pass through 2 or more specified points.  The sum of dur values
  1371. may or may not equal the instrument's performance time: a shorter
  1372. performance will truncate the specified pattern, while a longer
  1373. one.will cause the last-defined segment to continue on in the
  1374. same direction.  
  1375.  
  1376.  
  1377. Example: 
  1378.  
  1379.      k2   expseg 440, p3/2,880, p3/2,440 
  1380.  
  1381. This statement creates a control signal which moves exponentially
  1382. from 440 to 880 and back, over the duration p3.  
  1383.  
  1384.      kr   phasor    kcps[, iphs] 
  1385.      ar   phasor    xcps[, iphs] 
  1386.  
  1387. Produce a normalized moving phase value.  
  1388.  
  1389. INITIALIZATION 
  1390.  
  1391. iphs (optional) - initial phase, expressed as a fraction of a
  1392. cycle (0 to 1).  A negative value will cause phase initialization
  1393. to he skipped.  The default value is zero.  
  1394.  
  1395. PERFORMANCE 
  1396.  
  1397. An internal phase is successively accumulated in accordance with
  1398. the cps frequency to produce a moving phase value, normalized to
  1399. lie in the range 0.  <= phs < 1.  
  1400.  
  1401. When used as the index to a table unit, this phase (multiplied by
  1402. the desired function table length) will cause it to behave like
  1403. an oscillator.  
  1404.  
  1405. Note that phasor is a special kind of integrator, accumulating
  1406. phase increments that represent frequency settings.  
  1407.  
  1408.  
  1409. Example: 
  1410.  
  1411.           phasor         1                   ; cycle once per second
  1412.      kpch table          k1 * 12, 1          ; through 12-note pch table
  1413.      a1   oscil          p4, cpspch(kpch), 2 ; with continuous sound
  1414.  
  1415.      ir   table          indx, ifn[, ixmode][, ixoff][, iwrap]
  1416.      ir   tablei         indx, ifn[, ixmode][, ixoff][, iwrap]
  1417.      kr   table          kndx, ifn[, ixmode][, ixoff][, iwrap]
  1418.      kr   tablei         kndx, ifn[, ixmode][, ixoff][, iwrap]
  1419.      ar   table          andx, ifn[, ixmode][, ixoff][, iwrap]
  1420.      ar   tablei         andx, ifn[, ixmode][, ixoff][, iwrap]
  1421.      kr   oscil1         idel, kamp, idur, ifn
  1422.      kr   oscil1i        idel, kamp, idur, ifn
  1423.  
  1424. Table values are accessed by direct indexing or by incremental
  1425. sampling.  
  1426.  
  1427. INITIALIZATION 
  1428.  
  1429. ifn - function table number.  tablei, oscil1i require the
  1430. extended guard point.  
  1431.  
  1432. ixmode (optional) - ndx data mode.  0 = raw ndx, 1 = normalized
  1433. (0 to 1).  The default value is 0.  
  1434.  
  1435. ixoff (optional) - amount by which ndx is to be offset.  For a
  1436. table with origin at center, use tablesize/2 (raw) or .5
  1437. (normalized).  The default value is 0.  
  1438.  
  1439. iwrap (optional) - wraparound ndx flag.  0 = nowrap (ndx < 0
  1440. treated as ndx=0; ndx > tablesize sticks at ndx=size), 1 =
  1441. wraparound.  The default value is 0.  
  1442.  
  1443. idel - delay in seconds before oscil1 incremental sampling
  1444. begins.  
  1445.  
  1446. idur - duration in seconds to sample through the oscil1 table
  1447. just once.  A zero or negative value will cause all
  1448. initialization to be skipped.  
  1449.  
  1450. PERFORMANCE 
  1451.  
  1452. table invokes table lookup on behalf of init, control or audio
  1453. indices.  These indices can be raw entry numbers (0,l,2...size -
  1454. 1) or scaled values (0 to 1-e).  Indices are first modified by
  1455. the offset value then checked for range before table lookup (see
  1456. iwrap).  If ndx is likely to be full scale, or if interpolation
  1457. is being used, the table should have an extended guard point. 
  1458. table indexed by a periodic phasor (see phasor) will simulate an
  1459. oscillator.  
  1460.  
  1461. oscil1 accesses values by sampling once through the function
  1462. table at a rate determined by idur.  For the first idel seconds,
  1463. the point of scan will reside at the first location of the table;
  1464. it will then begin moving through the table at a constant rate,
  1465. reaching the end in another idur seconds; from that time on (i.e. 
  1466. after idel + idur seconds) it will remain pointing at the last
  1467. location.  Each value obtained from sampling is then multiplied
  1468. by an amplitude factor kamp before being written into the result. 
  1469.  
  1470.  
  1471. tablei and oscil1i are interpolating units in which the
  1472. fractional part of ndx is used to interpolate between adjacent
  1473. table entries.  The smoothness gained by interpolation is at some
  1474. small cost in execution time (see also oscili, etc.), but the
  1475. interpolating and non-interpolating units are otherwise
  1476. interchangeable.  Note that when tablei uses a periodic index
  1477. whose modulo n is less than the power of 2 table length, the
  1478. interpolation process requires that there be an (n + 1)th table
  1479. value that is a repeat of the 1st (see F statement in Score).  
  1480.  
  1481.      kr   oscil          kamp, kcps, ifn[, iphs]
  1482.      kr   oscili         kamp, kcps, ifn[, iphs]
  1483.      ar   oscil          xamp, xcps, ifn[, iphs]
  1484.      ar   oscili         xamp, xcps, ifn[, iphs]
  1485.      ar   foscil    xamp, kcps, kcar, kmod, kndx, ifn[, iphs]
  1486.      ar   foscili   xamp, kcps, kcar, kmod, kndx, ifn[, iphs]
  1487.  
  1488. Table ifn is incrementally sampled modulo the table length and
  1489. the value obtained is multiplied by amp.  
  1490.  
  1491. INITIALIZATION 
  1492.  
  1493. ifn - function table number.  Requires a wrap-around guard point. 
  1494.  
  1495.  
  1496. iphs (optional) - initial phase of sampling, expressed as a
  1497. fraction of a cycle (0 to 1).  A negative value will cause phase
  1498. initialization to be skipped.  The default value is 0.  
  1499.  
  1500. PERFORMANCE 
  1501.  
  1502. The oscil units output periodic control (or audio) signals
  1503. consisting of the value of kamp(xamp)times the value returned
  1504. from control rate (audio rate) sampling of a stored function
  1505. table.  The internal phase is simultaneously advanced in
  1506. accordance with the cps input value.  While the amplitude and
  1507. frequency inputs to the K-rate oscils are scalar only, the
  1508. corresponding inputs to the audio-rate oscils may each be either
  1509. scalar or vector, thus permitting amplitude and frequency
  1510. modulation at either sub-audio or audio frequencies.  
  1511.  
  1512. foscil is a composite unit that effectively banks two oscils in
  1513. the familiar Chowning FM setup, wherein the audio-rate output of
  1514. one generator is used to modulate the frequency input of another
  1515. (the "carrier").  Effective carrier frequency = kcps * kcar, and
  1516. modulating frequency = kcps * kmod.  For integral values of kcar
  1517. and kmod, the perceived fundamental will be the minimum positive
  1518. value of kcps  * (kcar - n * kmod), n = 1,1,2,...  The input kndx
  1519. is the index of modulation (usually time-varying and ranging 0 to
  1520. 4 or so) which determines the spread of acoustic energy over the
  1521. partial positions given by n = 0,1,2,.., etc.  ifn should point
  1522. to a stored sine wave.  
  1523.  
  1524. oscili and foscili differ from oscil and foscil respectively in
  1525. that the standard procedure of using a truncated phase as a
  1526. sampling index is here replaced by a process that interpolates
  1527. between two successive lookups.  Interpolating generators will
  1528. produce a noticeably cleaner output signal, but they may take as
  1529. much as twice as long to run.  Adequate accuracy can also be
  1530. gained without the time cost of interpolation by using large
  1531. stored function tables of 2K, 4K or 8K points if the space is
  1532. available.  
  1533.  
  1534.  
  1535. Example: 
  1536.  
  1537.      k1   oscil     10, 5, 1            ; 5 cps vibrato
  1538.      a1   oscil     5000, 440 + k1, 1   ; around A440 + -10 cps
  1539.  
  1540.       ar1 [,ar2]    loscil   xamp, kcps, ifn[, ibas][,imod1,ibeg1,iend1][, imod2,ibeg2,iend2]
  1541.  
  1542. Read sampled sound (mono or stereo) from a table, with optional
  1543. sustain and release looping.
  1544.  
  1545. INITIALIZATION 
  1546.  
  1547. ifn - function table number, typically denoting an AIFF sampled
  1548. sound segment with prescribed looping points.  The source file
  1549. may be mono or stereo.
  1550.  
  1551. ibas (optional) - base frequency in cps of the recorded sound. 
  1552. This optionally overrides the frequency given in the AIFF file,
  1553. but is required if the file did not contain one. The default
  1554. value is 0 (no override).
  1555.  
  1556. imod1, mod2 (optional) - play modes for the sustain and release
  1557. loops.  A value of 1 denotes normal looping, 2 denotes forward &
  1558. backward looping, 0 denotes no looping.  The default value (-1)
  1559. will defer to the mode and the looping points given in the source
  1560. file.
  1561.  
  1562. ibeg1, iend1, ibeg2, iend2 (optional, dependent on mod1, mod2) -
  1563. begin and end points of the sustain and release loops.  These are
  1564. measured in sample frames from the beginning of the file, so will
  1565. look the same whether the sound segment is monaural or stereo.
  1566.  
  1567. PERFORMANCE 
  1568.  
  1569. loscil samples the ftable audio at a rate determined by kcps,
  1570. then multiplies the result by xamp.  The sampling increment for
  1571. kcps is dependent on the table's base-note frequency ibas, and is
  1572. automatically adjusted if the orchestra sr value differs from
  1573. that at which the source was recorded.  In this unit, ftable is
  1574. always sampled with interpolation.
  1575.  
  1576. If sampling reaches the sustain loop endpoint and looping is in
  1577. effect, the point of sampling will be modified and loscil will
  1578. continue reading from within that loop segment.  Once the
  1579. instrument has received a turnoff signal (from the score or from
  1580. a MIDI noteoff event), the next sustain endpoint encountered will
  1581. be ignored and sampling will continue towards the release loop
  1582. end-point, or towards the last sample (henceforth to zeros).
  1583.  
  1584. locscil is the basic unit for building a sampling synthesizer. 
  1585. Given a sufficient set of recorded piano tones, for example, this
  1586. unit can resample them to simulate the missing tones.  Locating
  1587. the sound source nearest a desired pitch can be done via table
  1588. lookup.  Once a sampling instrument has begun, its turnoff point
  1589. may be unpredictable and require an external release envelope;
  1590. this is often done by gating the sampled audio with linenr, which
  1591. will extend the duration of a turned-off instrument by a specific
  1592. period while it implements a decay.
  1593.  
  1594.  
  1595. Example:
  1596.  
  1597.      inum notnum
  1598.      icps cpsmidi
  1599.      iamp ampmidi   3000, 1
  1600.      ifno table          inum, 2            ;notnum to choose an audio sample
  1601.      ibas table          inum, 3
  1602.      kamp linenr         iamp, 0, .05, .01  ;at noteoff, extend by 50 millisecs
  1603.      asig loscil         kamp, icps, ifno, cpsoct(ibas/12. + 3)
  1604.  
  1605.      ar   buzz      xamp, xcps, knh, ifn[, iphs]
  1606.      ar   gbuzz     xamp, xcps, knh, klh, kr, ifn[, iphs]
  1607.  
  1608. Output is a set of harmonically related cosine partials.  
  1609.  
  1610. INITIALIZATION 
  1611.  
  1612. ifn - table number of a stored function containing (for buzz) a
  1613. sine wave, or (for gbuzz) a cosine wave.  In either case a large
  1614. table of at least 8192 points is recommended.  
  1615.  
  1616. iphs (optional) - initial phase of the fundamental frequency,
  1617. expressed as a fraction of a cycle (0 to 1).  A negative value
  1618. will cause phase initialization to be skipped.  The default value
  1619. is zero.  
  1620.  
  1621. PERFORMANCE 
  1622.  
  1623. These units generate an additive set of harmonically related
  1624. cosine partials of fundamental frequency xcps, and whose
  1625. amplitudes are scaled so their summation peak equals xamp.  The
  1626. selection and strength of partials is determined by the following
  1627. control parameters: 
  1628.  
  1629. knh - total number of harmonics requested.  Must be positive.  
  1630.  
  1631. klh - lowest harmonic present.  Can be positive, zero or
  1632. negative.  In gbuzz the set of partials can begin at any partial
  1633. number and proceeds upwards; if klh is negative, all partials
  1634. below zero will reflect as positive partials without phase change
  1635. (since cosine is an even function), and will add constructively
  1636. to any positive partials in the set.  
  1637.  
  1638. kr - specifies the multiplier in the series of amplitude
  1639. coefficients.  This is a power series: if the klhth partial has a
  1640. strength coefficient of A, the (klh + n)th partial will have a
  1641. coefficient of A * (kr ** n), i.e.  strength values trace an
  1642. exponential curve.  kr may be positive, zero or negative, and is
  1643. not restricted to integers.  
  1644.  
  1645. buzz and gbuzz are useful as complex sound sources in subtractive
  1646. synthesis.  buzz is a special case of the more general gbuzz in
  1647. which klh = kr = 1; it thus produces a set of knh equal-strength
  1648. harmonic partials, beginning with the fundamental.  (This is a
  1649. band-limited pulse train; if the partials extend to the Nyquist,
  1650. i.e.  knh = int (sr / 2 / fundamental freq.), the result is a
  1651. real pulse train of amplitude xamp.)  Although both knh and klh
  1652. may be varied during performance, their internal values are
  1653. necessarily integer and may cause "pops" due to discontinuities
  1654. in the output; kr, however, can be varied during performance to
  1655. good effect.  Both buzz and gbuzz can be amplitude- and/or
  1656. frequency-modulated by either control or audio signals.  
  1657.  
  1658.  
  1659. N.B.  These two units have their analogs in GEN11, in which the
  1660. same set of cosines can be stored in a function table for
  1661. sampling by an oscillator.  Although computationally more
  1662. efficient, the stored pulse train has a fixed spectral content,
  1663. not a time-varying one as above.  
  1664.  
  1665.      ar   adsyn     kamod, kfmod, ksmod, ifilcod 
  1666.      ar   pvoc      ktimpnt, kfmod, ifilcod [, ispecwp]
  1667.  
  1668. Output is an additive set of individually controlled sinusoids,
  1669. using either an oscillator bank or phase vocoder resynthesis.  
  1670.  
  1671. INITIALIZATION 
  1672.  
  1673. ifilcod - integer or character-string denoting a control-file
  1674. derived from analysis of an audio signal.  An integer denotes the
  1675. suffix of a file adsyn.m or pvoc.m;  a character-string (in
  1676. double quotes) gives a filename, optionally a full pathname.  If
  1677. not fullpath, the file is sought first in the current directory,
  1678. then in the one given by the environment variable SADIR (if
  1679. defined).  adsyn control contains breakpoint amplitude- and
  1680. frequency-envelope values organized for oscillator resynthesis,
  1681. while pvoc control contains similar data organized for fft
  1682. resynthesis.  Memory usage depends on the size of the files
  1683. involved, which are read and held entirely in memory during
  1684. computation but are shared by multiple calls (see also lpread).
  1685.  
  1686. ispecwp (optional) - if non-zero, attempts to preserve the
  1687. spectral envelope while its frequency content is varied by kfmod. 
  1688.   The default value is zero.
  1689.  
  1690. PERFORMANCE 
  1691.  
  1692. adsyn synthesizes complex time-varying timbres through the method
  1693. of additive synthesis.  Any number of sinusoids, each
  1694. individually controlled in frequency and amplitude, can be summed
  1695. by high-speed arithmetic to produce a high-fidelity result.  
  1696.  
  1697. Component sinusoids are described by a control file describing
  1698. amplitude and frequency tracks in millisecond breakpoint fashion.
  1699. Tracks are defined by sequences of 16-bit binary integers:
  1700.                -1, time, amp, time, amp,...
  1701.                -2, time, freq, time, freq,...
  1702. such as from hetrodyne filter analysis of an audio file. (For
  1703. details see the Appendix on hetro.)  The instantaneous amplitude
  1704. and frequency values are used by an internal fixed-point
  1705. oscillator that adds each active partial into an accumulated
  1706. output signal.  While there is a practical limit (currently 50)
  1707. on the number of contributing partials, there is no restriction
  1708. on their behavior over time.  Any sound that can be described in
  1709. terms of the behavior of sinusoids can be synthesized by adsyn
  1710. alone.  
  1711.  
  1712. Sound described by an adsyn control file can also be modified
  1713. during re-synthesis.  The signals kamod, kfmod, ksmod will modify
  1714. the amplitude, frequency, and speed of contributing partials. 
  1715. These are multiplying factors, with kfmod modifying the cps
  1716. frequency and ksmod modifying the speed with which the
  1717. millisecond bread-point line-segments are traversed.  Thus .7,
  1718. 1.5, and 2 will give rise to a softer sound, a perfect fifth
  1719. higher, but only half as long.  The values 1,1,1 will leave the
  1720. sound unmodified.  Each of these inputs can be a control signal.  
  1721.  
  1722. pvoc implements signal reconstruction using an fft-based phase
  1723. vocoder.  The control data stems from a precomputed analysis file
  1724. with a known frame rate.  The passage of time through this file
  1725. is specified by ktimpnt, which represents the time in seconds. 
  1726. ktimpnt must always be positive, but can move forwards or
  1727. backwards in time, be stationary or discontinuous, as a pointer
  1728. into the analysis file.  kfmod is a control-rate transposition
  1729. factor: a value of 1 incurs no transposition, 1.5 transposes up a
  1730. perfect fifth, and .5 down an octave.  
  1731.  
  1732. This implementation of pvoc was written by Dan Ellis.  It is
  1733. based in part on the system of Mark Dolson, but the pre-analysis
  1734. concept is new.  
  1735.  
  1736.      ar   fof  xamp, xfund, xform, koct, kband, kris, kdur, kdec,
  1737.                     iolaps, ifna, ifnb, itotdur[, iphs][, ifmode] 
  1738.  
  1739. Audio output is a succession of sinusoid bursts initiated at
  1740. frequency xfund with a spectral peak at xform.  For xfund above
  1741. 25 Hz these bursts produce a speech-like formant with spectral
  1742. characteristics determined by the k-input parameters.  For lower
  1743. fundamentals this generator provides a special form of granular
  1744. synthesis.  
  1745.  
  1746. INITIALIZATION 
  1747.  
  1748. iolaps - number of preallocated spaces needed to hold overlapping
  1749. burst data.  Overlaps are frequency dependent, and the space
  1750. required depends on the maximum value of xfund * kdur.   Can be
  1751. over-estimated at no computation cost.  Uses less than 50 bytes
  1752. of memory per iolap.
  1753.  
  1754. ifna, ifnb - table numbers of two stored functions.  The first is
  1755. a sine table for sineburst synthesis (size of at least 4096
  1756. recommended).  The second is a rise shape, used forwards and
  1757. backwards to shape the sineburst rise and decay;  this may be
  1758. linear (GEN07) or perhaps a sigmoid (GEN19).
  1759.  
  1760. itotdur - total time during which this fof will be active. 
  1761. Normally set to p3.  No new sineburst is created if it cannot
  1762. complete its kdur within the remaining itotdur.
  1763.  
  1764. iphs (optional) - initial phase of the fundamental, expressed as
  1765. a fraction of a cycle (0 to 1).  The default value is 0.
  1766.  
  1767. ifmode (optional) - formant frequency mode. If zero, each
  1768. sineburst keeps the xform frequency it was launched with.  If
  1769. non-zero, each is influenced by xform continuously.  The default
  1770. value is 0.
  1771.  
  1772. PERFORMANCE
  1773.  
  1774. xamp - peak amplitude of each sineburst, observed at the true end
  1775. of its rise pattern.  The rise may exceed this value given a
  1776. large bandwidth (say, Q < 10) and/or when the bursts are
  1777. overlapping.
  1778.  
  1779. xfund - the fundamental frequency (in Hertz) of the impulses that
  1780. create new sinebursts.
  1781.  
  1782. xform - the formant frequency, i.e. freq of the sinusoid burst
  1783. induced by each xfund impulse.  This frequency can be fixed for
  1784. each burst or can vary continuously (see ifmode).
  1785.  
  1786. koct - octaviation index, normally zero.  If greater than zero,
  1787. lowers the effective xfund frequency by attenuating odd-numbered
  1788. sinebursts.  Whole numbers are full octaves, fractions
  1789. transitional.
  1790.  
  1791. kband - the formant bandwidth (at -6dB), expressed in Hz.  The
  1792. bandwidth determines the rate of exponential decay throughout the
  1793. sineburst, before the enveloping described below is applied.
  1794.  
  1795. kris, kdur, kdec - rise, overall duration, and decay times (in
  1796. seconds) of the sinusoid burst.  These values apply an enveloped
  1797. duration to each burst, in similar fashion to a Csound linen
  1798. generator  but with rise and decay shapes derived from the ifnb
  1799. input.  kris inversely determines the skirtwidth (at -40 dB) of
  1800. the induced formant region.  kdur affects the density of
  1801. sineburst overlaps, and thus the speed of computation.  Typical
  1802. values for vocal imitation are .003,.02,.007. 
  1803.  
  1804. Csound's fof generator is loosely based on Michael Clarke's
  1805. C-coding of IRCAM's CHANT program (Xavier Rodet et al.).  Each
  1806. fof produces a single formant, and the output of four or more of
  1807. these can be summed to produce a rich vocal imitation.  fof
  1808. synthesis is a special form of granular synthesis, and this
  1809. implementation aids transformation between vocal imitation and
  1810. granular textures.  Computation speed depends on kdur, xfund, and
  1811. the density of any overlaps.
  1812.  
  1813.      ar   pluck     kamp, kcps, icps, ifn, imeth [, iparm1, iparm2] 
  1814.  
  1815. Audio output is a naturally decaying plucked string or drum sound
  1816. based on the Karplus-Strong algorithms.  
  1817.  
  1818. INITIALIZATION 
  1819.  
  1820. icps - intended pitch value in cps, used to set up a buffer of 1
  1821. cycle of audio samples which will be smoothed over time by a
  1822. chosen decay method.  icps normally anticipates the value of
  1823. kcps, but may be set artificially high or low to influence the
  1824. size of the sample buffer.  
  1825.  
  1826. ifn - table number of a stored function used to initialize the
  1827. cyclic decay buffer.  If ifn = 0, a random sequence will be used
  1828. instead.  
  1829.  
  1830. imeth - method of natural decay.  There are six, some of which
  1831. use parameters values that follow.  
  1832.  
  1833. 1 - simple averaging.  A simple smoothing process, uninfluenced
  1834.      by parameter values.  
  1835. 2 - stretched averaging.  As above, with smoothing time stretched
  1836.      by a factor of iparm1 ( >= 1 ).  
  1837. 3 - simple drum.  The range from pitch to noise is controlled by a 
  1838.      'roughness factor' in iparm1 (0 to 1).  Zero gives the plucked 
  1839.      string effect, while 1 reverses the polarity of every sample 
  1840.      (octave down, odd harmonics).  The setting .5 gives an optimum 
  1841.      snare drum.  
  1842. 4 - stretched drum.  Combines both roughness and stretch factors. 
  1843.      iparm1 is roughness (0 to 1),      
  1844.      and iparm2 the stretch factor ( >= 1 ).  
  1845. 5 - weighted averaging.  As method 1, with iparm1 weighting the
  1846.      current sample (the status quo)    and iparm2 weighting the
  1847.      previous adjacent one.  iparm1 + iparm2 must be <= 1.  
  1848. 6 - 1st order recursive filter, with coefs .5.  Unaffected by
  1849.      parameter values.  
  1850.  
  1851. iparm1, iparm2 (optional) - parameter values for use by the
  1852. smoothing algorithms (above).  The default values are both 0.  
  1853.  
  1854. PERFORMANCE 
  1855.  
  1856. An internal audio buffer, filled at I-time according to ifn, is
  1857. continually resampled with periodicity kcps and the resulting
  1858. output is multiplied by kamp.  Parallel with the sampling, the
  1859. buffer is smoothed to simulate the effect of natural decay.  
  1860.  
  1861. Plucked strings (1,2,5,6) are best realized by starting with a
  1862. random noise source, which is rich in initial harmonics.  Drum
  1863. sounds (methods 3,4) work best with a flat source (wide pulse),
  1864. which produces a deep noise attack and sharp decay.  
  1865.  
  1866. The original Karplus-Strong algorithm used a fixed number of
  1867. samples per cycle, which caused serious quantization of the
  1868. pitches available and their intonation.  This implementation
  1869. resamples a buffer at the exact pitch given by kcps, which can be
  1870. varied for vibrato and glissando effects.  For low values of the
  1871. orch sampling rate (e.g.  sr = 10000), high frequencies will
  1872. store only very few samples (sr / icps).  Since this may cause
  1873. noticeable noise in the resampling process, the internal buffer
  1874. has a minimum size of 64 samples.  This can be further enlarged
  1875. by setting icps to some artificially lower pitch.  
  1876.  
  1877.      kr   rand      xamp[, iseed]
  1878.      kr   randh     kamp, kcps[, iseed]
  1879.      kr   randi     kamp, kcps[, iseed]
  1880.      ar   rand      xamp[, iseed]
  1881.      ar   randh     xamp, xcps[, iseed]
  1882.      ar   randi     xamp, xcps[, iseed]
  1883.  
  1884. Output is a controlled random number series between +amp and -amp 
  1885.  
  1886. INITIALIZATION
  1887.  
  1888. iseed (optional) - seed value for the recursive psuedo-random
  1889. formula.  A value between 0 and +1 will produce an initial output
  1890. of kamp * iseed A negative value will cause seed
  1891. re-initialization to be skipped.  The default seed value is .5.  
  1892.  
  1893. PERFORMANCE 
  1894.  
  1895. The internal psuedo-random formula produces values which are
  1896. uniformly distributed over the range kamp to -kamp.  rand will
  1897. thus generate uniform white noise with an R.M.S value of kamp /
  1898. root 2.  
  1899.  
  1900. The remaining units produce band-limited noise: the cps
  1901. parameters permit the user to specify that new random numbers are
  1902. to be generated at a rate less than the sampling or control
  1903. frequencies.  randh will hold each new number for the period of
  1904. the specified cycle; randi will produce straightline
  1905. interpolation between each new number and the next.  
  1906.  
  1907.  
  1908. Example: 
  1909.  
  1910.      i1   =    octpch(p5)     ; center pitch, to be modified
  1911.      k1   randh     1,10      ;10 time/sec by random displacements up to 1 octave
  1912.      a1   oscil     5000, cpsoct(i1+k1), 1
  1913.  
  1914. SIGNAL MODIFIERS 
  1915.  
  1916.      kr   linen          kamp, irise, idur, idec
  1917.      ar   linen          xamp, irise, idur, idec
  1918.      kr   linenr    kamp, irise, idec, iatdec
  1919.      ar   linenr    xamp, irise, idec, iatdec
  1920.      kr   envlpx    kamp, irise, idur, idec, ifn, iatss, iatdec[,ixmod]
  1921.      ar   envlpx    xamp, irise, idur, idec, ifn, iatss, iatdec[,ixmod]
  1922.  
  1923. linen - apply a straight line rise and decay pattern to an input amp signal.  
  1924. linenr - apply a straight line rise, then an exponential decay while the note is extended in time.
  1925. envlpx - apply an envelope consisting of 3 segments: 1) stored function rise shape, 2) modified 
  1926.           exponential "pseudo steady state", 3) exponential decay 
  1927.  
  1928. INITIALIZATION 
  1929.  
  1930. irise - rise time in seconds.  A zero or negative value signifies
  1931. no rise modification.  
  1932.  
  1933. idur - overall duration in seconds.  A zero or negative value
  1934. will cause initialization to be skipped.  
  1935.  
  1936. idec - decay time in seconds.  Zero means no decay.  An idec >
  1937. idur will cause a truncated decay.
  1938.  
  1939. ifn - function table number of stored rise shape with extended
  1940. guard point.  
  1941.  
  1942. iatss - attenuation factor, by which the last value of the envlpx
  1943. rise is modified during the note's pseudo "steady state."  A
  1944. factor > l causes an exponential growth, and < l an exponential
  1945. decay.  A 1 will maintain a true steady state at the last rise
  1946. value.  Note that this attenuation is not by fixed rate (as in a
  1947. piano), but is sensitive to a note's duration.  However, if iatss
  1948. is negative (or if "steady state" < 4 k-periods) a fixed
  1949. attenuation rate of abs(iatss) per second will be used.  0 is
  1950. illegal.  
  1951.  
  1952. iatdec - attenuation factor by which the closing "steady state"
  1953. value is reduced exponentially over the decay period.  This value
  1954. must be positive and is normally of the order of .01.  A large or
  1955. excessively small value is apt to produce a cutoff which is
  1956. audible.  A zero or neg value is illegal.  
  1957.  
  1958. ixmod (optional, between +- .9 or so) - exponential curve
  1959. modifier, influencing the "steepness" of the exponential
  1960. trajectory during the "steady state." Values less than zero will
  1961. cause an accelerated growth or decay towards the target (e.g. 
  1962. subito piano).  Values greater than zero will cause a retarded
  1963. growth or decay.  The default value is zero (unmodified
  1964. exponential).  
  1965.  
  1966. PERFORMANCE 
  1967.  
  1968. Rise modifications are applied for the first irise seconds, and
  1969. decay from time idur - idec.  If these periods are separated in
  1970. time there will be a "steady state" during which amp will be
  1971. unmodified (linen) or modified by the first exponential pattern
  1972. (envlpx).  If linen rise and decay periods overlap then both
  1973. modifications will be in effect for that time; in envlpx that
  1974. will cause a truncated decay.  If the overall duration idur is
  1975. exceeded in performance, the final decay will continue on in the
  1976. same direction, going negative for linen but tending
  1977. asymptotically to zero in envlpx.
  1978.  
  1979. linenr is unique within Csound in containing a note-off sensor
  1980. and release time extender. When it senses either a score event
  1981. termination or a MIDI noteoff, it will immediately extend the
  1982. performance time of the current instrument by idec seconds, then
  1983. execute an exponential decay towards the factor iatdec.  For two
  1984. or more units in an instrument, extension is by the greatest
  1985. idec.
  1986.  
  1987.      kr   port      ksig, ihtim[, isig]
  1988.      ar   tone      asig, khp[, istor]
  1989.      ar   atone     asig, khp[, istor]
  1990.      ar   reson     asig, kcf, kbw[, iscl, istor]
  1991.      ar   areson    asig, kcf, kbw[, iscl, istor]
  1992.  
  1993. A control or audio signal is modified by a low- or band-pass
  1994. recursive filter with variable frequency response.  
  1995.  
  1996. INITIALIZATION
  1997.  
  1998. isig - initial (i.e. previous) value for internal feedback.  The
  1999. default value is 0.  
  2000.  
  2001. istor - initial disposition of internal data space.  Since
  2002. filtering incorporates a feedback loop of previous output, the
  2003. initial status of the storage space used is significant.  A zero
  2004. value will clear the space;  a non-zero value will allow previous
  2005. information to remain.  The default value is 0.  
  2006.  
  2007. iscl - coded scaling factor for resonators.  A value of 1
  2008. signifies a peak response factor of 1, i.e.  all frequencies
  2009. other than kcf are attenuated in accordance with the (normalized)
  2010. response curve.  A value of 2 raises the response factor so that
  2011. its overall RMS value equals 1.  (This intended equalization of
  2012. input and output power assumes all frequencies are physically
  2013. present; hence it is most applicable to white noise.)  A zero
  2014. value signifies no scaling of the signal, leaving that to some
  2015. later adjustment (e.g. see balance).  The default value is 0.  
  2016.  
  2017. PERFORMANCE 
  2018.  
  2019. port applies portamento to a step-valued control signal.  At each
  2020. new step value, ksig is low-pass filtered to move towards that
  2021. value at a rate determined by ihtim.  ihtim is the "half-time" of
  2022. the function (in seconds), during which the curve will traverse
  2023. half the distance towards the new value, then half as much again,
  2024. etc., theoretically never reaching its asymptote.  
  2025.  
  2026. tone implements a first-order recursive low-pass filter in which
  2027. the variable khp (in cps) determines the response curve's half
  2028. -power point.  Half power is defined as peak power / root 2.  
  2029.  
  2030. reson is a second-order filter in which kcf controls the center
  2031. frequency, or cps position of the peak response, and kbw controls
  2032. its bandwidth (the cps difference between the upper and lower
  2033. half -power points).  
  2034.  
  2035. atone, areson are filters whose transfer functions are the
  2036. complements of tone and reson.  atone is thus a form of high-pass
  2037. filter and areson a notch filter whose transfer functions
  2038. represent the "filtered out" aspects of their complements.  Note,
  2039. however, that power scaling is not normalized in atone, areson,
  2040. but remains the true complement of the corresponding unit.  Thus
  2041. an audio signal, filtered by parallel matching reson and areson
  2042. units, would under addition simply reconstruct the original
  2043. spectrum.  This property is particularly useful for controlled
  2044. mixing of different sources (e.g., see lpreson).  
  2045.  
  2046. Complex response curves such as those with multiple peaks can be
  2047. obtained by using a bank of suitable filters in series.  (The
  2048. resultant response is the product of the component responses.) In
  2049. such cases, the combined attenuation may result in a serious loss
  2050. of signal power, but this can be regained by the use of balance.  
  2051.  
  2052.   krmsr,krmso,kerr,kcps  lpread    ktimpnt, ifilcod[, inpoles][,
  2053. ifrmrate] 
  2054.                ar   lpreson   asig 
  2055.                ar   lpfreson  asig, kfrqratio 
  2056.  
  2057. These units, used as a read/reson pair, use a control file of
  2058. time-varying filter coefficients to dynamically modify the
  2059. spectrum of an audio signal.  
  2060.  
  2061. INITIALIZATION 
  2062.  
  2063. ifilcod - integer or character-string denoting a control-file
  2064. (reflection coefficients and four parameter values) derived from
  2065. n-pole linear predictive spectral analysis of a source audio
  2066. signal.  An integer denotes the suffix of a file lp.m;  a
  2067. character-string (in double quotes) gives a filename, optionally
  2068. a full pathname.  If not fullpath, the file is sought first in
  2069. the current directory, then in that of the environment variable
  2070. SADIR (if defined).  Memory usage depends on the size of the
  2071. file, which is held entirely in memory during computation but
  2072. shared by multiple calls (see also adsyn, pvoc).
  2073.  
  2074. inpoles, ifrmrate (optional) - number of poles, and frame rate
  2075. per second in the lpc analysis.  These arguments are required
  2076. only when the control file does not have a header; they are
  2077. ignored when a header is detected.  The default value for both is
  2078. zero.  
  2079.  
  2080. PERFORMANCE 
  2081.  
  2082. lpread accesses a control file of time-ordered information
  2083. frames, each containing n-pole filter coefficients derived from
  2084. linear predictive analysis of a source signal at fixed time
  2085. intervals (e.g.  1/100 of a second), plus four parameter values: 
  2086.           krmsr - root-mean-square (rms) of the residual of analysis, 
  2087.           krmso - rms of the original signal, 
  2088.           kerr - the normalized error signal, 
  2089.           kcps - pitch in cps.  
  2090. lpread gets its values from the control file according to the
  2091. input value ktimpnt (in seconds).  If ktimpnt proceeds at the
  2092. analysis rate, time-normal synthesis will result; proceeding at a
  2093. faster, slower, or variable rate will result in time-warped
  2094. synthesis.  At each K-period, lpread interpolates between
  2095. adjacent frames to more accurately determine the parameter values
  2096. (presented as output) and the filter coefficient settings (passed
  2097. internally to a subsequent lpreson).  
  2098.  
  2099. The error signal kerr (between 0 and 1) derived during predictive
  2100. analysis reflects the deterministic/random nature of the analyzed
  2101. source.  This will emerge low for pitched (periodic) material and
  2102. higher for noisy material.  The transition from voiced to
  2103. unvoiced speech, for example, produces an error signal value of
  2104. about .3.  During synthesis, the error signal value can be used
  2105. to determine the nature of the lpreson driving function: for
  2106. example, by arbitrating between pitched and non-pitched input, or
  2107. even by determining a mix of the two.  In normal speech
  2108. resynthesis, the pitched input to lpreson is a wideband periodic
  2109. signal or pulse train derived from a unit such as buzz, and the
  2110. nonpitched source is usually derived from rand.  However, any
  2111. audio signal can be used as the driving function, the only
  2112. assumption of the analysis being that it has a flat response.  
  2113.  
  2114. lpfreson is a formant shifted lpreson, in which kfrqratio is the
  2115. (cps) ratio of shifted to original formant positions.  This
  2116. permits synthesis in which the source object changes its apparent
  2117. acoustic size.  lpfreson with kfrqratio = 1 is equivalent to
  2118. lpreson.  
  2119.  
  2120. Generally, lpreson provides a means whereby the time-varying
  2121. content and spectral shaping of a composite audio signal can be
  2122. controlled by the dynamic spectral content of another.  There can
  2123. be any number of lpread/lpreson (or lpfreson) pairs in an
  2124. instrument or in an orchestra; they can read from the same or
  2125. different control files independently.  
  2126.  
  2127.      kr   rms       asig[, ihp, istor]
  2128.      nr   gain      asig, krms[, ihp, istor]
  2129.      ar   balance   asig, acomp[, ihp, istor]
  2130.  
  2131. The rms power of asig can be interrogated, set, or adjusted to
  2132. match that of a comparator signal.  
  2133.  
  2134. INlTlALIZATlON 
  2135.  
  2136. ihp (optional) - half-power point (in cps) of a special internal
  2137. low-pass filter.  The default value is 10.  
  2138.  
  2139. istor (optional) - initial disposition of internal data space
  2140. (see reson).  The default value is 0.  
  2141.  
  2142. PERFORMANCE 
  2143.  
  2144. rms output values kr will trace the rms value of the audio input
  2145. asig.  This unit is not a signal modifier,  but functions rather
  2146. as a signal power-guage.  
  2147.  
  2148. gain provides an amplitude modification of asig so that the
  2149. output ar has rms power equal to krms.  rms and gain used
  2150. together (and given matching ihp values) will provide the same
  2151. effect as balance.  
  2152.  
  2153. balance outputs a version of asig, amplitude-modified so that its
  2154. rms power is equal to that of a comparator signal acomp.  Thus a
  2155. signal that has suffered loss of power (eg., in passing through a
  2156. filter bank) can be restored by matching it with, for instance,
  2157. its own source.  It should be noted that gain and balance provide
  2158. amplitude modification only - output signals are not altered in
  2159. any other respect.  
  2160.  
  2161.  
  2162. Example: 
  2163.  
  2164.      asrc buzz      10000,440, sr/440, 1     ; band-limited pulse train
  2165.      a1   reson     asrc, 1000,100           ; sent through
  2166.      a2   reson     a1,3000,500              ; 2 filters
  2167.      afin balance   a2, asrc                 ; then balanced with
  2168. source
  2169.  
  2170.      kr   downsamp  asig[, iwlen]
  2171.      ar   upsamp    ksig 
  2172.      ar   interp    ksig[, istor]
  2173.      kr   integ     ksig[, istor]
  2174.      ar   integ     asig[, istor]
  2175.      kr   diff      ksig[, istor]
  2176.      ar   diff      asig[, istor]
  2177.      kr   samphold  xsig, kgate[, ival, ivstor]
  2178.      ar   samphold  asig, xgate[, ival, ivstor]
  2179.  
  2180. Modify a signal by up- or down-sampling, integration, and
  2181. differentiation.  
  2182.  
  2183. INITIALIZATION
  2184.  
  2185. iwlen (optional) - window length in samples over which the audio
  2186. signal is averaged to determine a downsampled value.  Maximum
  2187. length is ksmps; 0 and 1 imply no window averaging.   The default
  2188. value is 0.  
  2189.  
  2190. istor (optional) - initial disposition of internal save space
  2191. (see reson).  The default value is 0.  
  2192.  
  2193. ival, ivstor (optional) - controls initial disposition of
  2194. internal save space.  If ivstor is zero the internal "hold" value
  2195. is set to ival ; else it retains its previous value.  Defaults
  2196. are 0,0 (i.e.  init to zero).  
  2197.  
  2198. PERFORMANCE
  2199.  
  2200. downsamp converts an audio signal to a control signal by
  2201. downsampling.  It produces one kval for each audio control
  2202. period.  The optional window invokes a simple averaging process
  2203. to suppress foldover.  
  2204.  
  2205. upsamp, interp convert a control signal to an audio signal.  The
  2206. first does it by simple repetition of the kval, the second by
  2207. linear interpolation between successive kvals.  upsamp is a
  2208. slightly more efficient form of the assignment, `asig = ksig'.  
  2209.  
  2210. integ, diff perform integration and differentiation on an input
  2211. control signal or audio signal.  Each is the converse of the
  2212. other, and applying both will reconstruct the original signal. 
  2213. Since these units are special cases of low-pass and high-pass
  2214. filters, they produce a scaled (and phase shifted) output that is
  2215. frequency-dependent.  Thus diff of a sine produces a cosine, with
  2216. amplitude 2 * sin(pi * cps / sr) that of the original (for each
  2217. component partial); integ will inversely affect the magnitudes of
  2218. its component inputs.  With this understanding, these units can
  2219. provide useful signal modification.  
  2220.  
  2221. samphold performs a sample-and-hold operation on its input
  2222. according to the value of gate.  If gate > 0, the input samples
  2223. are passed to the output;  If gate <= 0, the last output value is
  2224. repeated.  The controlling gate can be a constant, a control
  2225. signal, or an audio signal.  
  2226.  
  2227. Example: 
  2228.  
  2229.      asrc buzz      10000,440,20, 1     ; band-limited pulse train
  2230.      adif diff      asrc                ; emphasize the highs
  2231.      anew balance   adif, asrc          ;    but retain the power
  2232.      agate reson    asrc,0,440          ; use a lowpass of the original
  2233.      asamp samphold anew, agate         ;       to gate the new audiosig
  2234.      aout tone      asamp,100           ; smooth out the rough edges
  2235.  
  2236.      ar   delayr    idlt[, istor]
  2237.           delayw    asig
  2238.      ar   delay          asig, idlt[, istor]
  2239.      ar   delay1    asig[, istor]
  2240.  
  2241. A signal can be read from or written into a delay path, or it can
  2242. be automatically delayed by some time interval.  
  2243.  
  2244. INITIALIZATION 
  2245.  
  2246. idlt - requested delay time in seconds.  This can be as large as
  2247. available memory will permit.  The space required for n seconds
  2248. of delay is 4n * sr bytes.  It is allocated at the time the
  2249. instrument is first initialized, and returned to the pool at the
  2250. end of a score section.  
  2251.  
  2252. istor (optional) - initial disposition of delay-loop data space
  2253. (see reson).  The default value is 0.  
  2254.  
  2255.  
  2256. PERFORMANCE 
  2257.  
  2258. delayr reads from an automatically established digital delay
  2259. line, in which the signal retrieved has been resident for idlt
  2260. seconds.  This unit must be paired with and precede an
  2261. accompanying delayw unit.  Any other Csound statements can
  2262. intervene.  
  2263.  
  2264. delayw writes asig into the delay area established by the
  2265. preceding delayr unit.  Viewed as a pair, these two units permit
  2266. the formation of modified feedback loops, etc.  However, there is
  2267. a lower bound on the value of idlt, which must be at least 1
  2268. control period (or 1/kr).  
  2269.  
  2270. delay is a composite of the above two units, both reading from
  2271. and writing into its own storage area.  It can thus accomplish
  2272. signal time-shift, although modified feedback is not possible. 
  2273. There is no minimum delay period.  
  2274.  
  2275. delay1 is a special form of delay that serves to delay the audio
  2276. signal asig by just one sample.  It is thus functionally
  2277. equivalent to "delay  asig, 1/sr" but is more efficient in both
  2278. time and space.  This unit is particularly useful in the
  2279. fabrication of generalized non-recursive filters.  
  2280.  
  2281.  
  2282. Example: 
  2283.  
  2284.           tigoto    contin         ; except on a tie,
  2285.      a2   delay     a1, .05, 0     ; begin 50 msec clean delay of sig
  2286.      contin:
  2287.  
  2288.      ar   deltap    kdlt
  2289.      ar   deltapi   xdlt 
  2290.  
  2291. Tap a delay line at variable offset times.  
  2292.  
  2293. PERFORMANCE 
  2294.  
  2295. These units can tap into a delayr/delayw pair, extracting delayed
  2296. audio from the idlt seconds of stored sound.  There can be any
  2297. number of deltap and/or deltapi units between a read/write pair. 
  2298. Each receives an audio tap with no change of original amplitude.  
  2299.  
  2300. deltap extracts sound by reading the stored samples directly;
  2301. deltapi extracts sound by interpolated readout.  By interpolating
  2302. between adjacent stored samples deltapi represents a particular
  2303. delay time with more accuracy, but it will take about twice as
  2304. long to run.  
  2305.  
  2306. The arguments kdlt, xdlt specify the tapped delay time in
  2307. seconds.  Each can range from 1 Control Period to the full delay
  2308. time of the read/write pair; however, since there is no internal
  2309. check for adherence to this range, the user is wholly
  2310. responsible.  Each argument can be a constant, a variable, or a
  2311. time-varying signal; the xdlt argument in deltapi implies that an
  2312. audio-varying delay is permitted there.  
  2313.  
  2314. These units can provide multiple delay taps for arbitrary delay
  2315. path and feedback networks.  They can deliver either
  2316. constant-time or time-varying taps, and are useful for building
  2317. chorus effects, harmonizers, and doppler shifts.  Constant-time
  2318. delay taps (and some slowly changing ones) do not need
  2319. interpolated readout; they are well served by deltap. 
  2320. Medium-paced or fast varying dlt's, however, will need the extra
  2321. services of deltapi.  
  2322.  
  2323. N.B. K-rate delay times are not internally interpolated, but
  2324. rather lay down stepped time-shifts of audio samples; this will
  2325. be found quite adequate for slowly changing tap times.  For
  2326. medium to fastpaced changes, however, one should provide a higher
  2327. resolution audio-rate timeshift as input.  
  2328.  
  2329.  
  2330. Example: 
  2331.  
  2332.      asource   buzz      1, 440, 20, 1 
  2333.      atime     linseg    1, p3/2,.01, p3/2,1 ; trace a distance in secs
  2334.      ampfac    =    1/atime/atime       ;     and calc an amp factor
  2335.      adump     delayr    1              ; set maximum distance 
  2336.      amove     deltapi   atime          ; move sound source past
  2337.                delays    asource        ;     the listener
  2338.                out  amove * ampfac
  2339.  
  2340.      ar   comb      asig, krvt, ilpt[, istor]
  2341.      ar   alpass    asig, krvt, ilpt[, istor]
  2342.      ar   reverb    asig, krvt[, istor]
  2343.  
  2344. An input signal is reverberated for krvt seconds with "colored"
  2345. (comb), flat (alpass), or "natural room" (reverb) frequency
  2346. response.  
  2347.  
  2348. INITIALIZATION 
  2349.  
  2350. ilpt - loop time in seconds, which determines the "echo density"
  2351. of the reverberation.  This in turn characterizes the "color" of
  2352. the comb filter whose frequency response curve will contain ilpt
  2353. * sr/2 peaks spaced evenly between 0 and sr/2 (the Nyquist
  2354. frequency).  Loop time can be as large as available memory will
  2355. permit.  The space required for an n second loop is 4n * sr
  2356. bytes.  comb and alpass delay space is allocated and returned as
  2357. in delay.  
  2358.  
  2359. istor (optional) - initial disposition of delay-loop data space
  2360. (cf.  reson).  The default value is 0.  
  2361.  
  2362. PERFORMANCE 
  2363.  
  2364. These filters reiterate input with an echo density determined by
  2365. loop time ilpt.  The attenuation rate is independent and is
  2366. determined by krvt, the reverberation time (defined as the time
  2367. in seconds for a signal to decay to 1/1000, or 60dB down from its
  2368. original amplitude).  Output from a comb filter will appear only
  2369. after ilpt seconds; alpass output will begin to appear
  2370. immediately.  
  2371.  
  2372. A standard reverb unit is composed of four comb filters in
  2373. parallel followed by two alpass units in series.  Looptimes are
  2374. set for optimal "natural room response." Core storage
  2375. requirements for this unit are proportional only to the sampling
  2376. rate, each unit requiring approximately 3K words for every 10KC. 
  2377. The comb, alpass, delay, tone and other Csound units provide the
  2378. means for experimenting with alternate reverberator designs 
  2379.  
  2380. Since output from the standard reverb will begin to appear only
  2381. after 1/20 second or so of delay, and often with less than
  2382. three-fourths of the original power, it is normal to output both
  2383. the source and the reverberated signal.  Also, since the
  2384. reverberated sound will persist long after the cessation of
  2385. source events, it is normal to put reverb in a separate
  2386. instrument to which sound is passed via a global variable, and to
  2387. leave that instrument running throughout the performance.
  2388.  
  2389.  
  2390. Example: 
  2391.  
  2392.      ga1  init 0              ; init an audio receiver/mixer
  2393.  
  2394.           instr     1         ; instr (there may be many copies)
  2395.      a1   oscili    8000, cpspch(p5), 1 ; generate a source signal
  2396.           out  a1             ; output the direct sound
  2397.      ga1  =    ga1 + a1       ; and add to audio receiver
  2398.           endin
  2399.  
  2400.           instr     99        ; (highest instr number executed last)
  2401.      a3   reverb    ga1, 1.5  ; reverberate whatever is in ga1
  2402.           out  a1             ; and output the result
  2403.      ga1  =    0              ; empty the receiver for the next pass
  2404.           endin
  2405.  
  2406. OPERATIONS USING SPECTRAL DATA-TYPES 
  2407.  
  2408. These units generate and process non-standard signal data types,
  2409. such as down-sampled time-domain control signals and audio
  2410. signals, and their frequency-domain (spectral) representations. 
  2411. The new data types (d-, w-) are self-defining, and the contents
  2412. are not processable by any other Csound units.  These unit
  2413. generators are experimental, and subject to change between
  2414. releases; they will also be joined by others later.
  2415.  
  2416.  
  2417.      dsig octdown   xsig, iocts, isamps[, idisprd]
  2418.      wsig noctdft   dsig, iprd, ifrqs, iq[, ihann, idbout,
  2419. idsines]
  2420.  
  2421. INITIALIZATION 
  2422.  
  2423. idisprd (optional) - if non-zero, display the output every
  2424. idisprd seconds.  The default value is 0 (no display).  
  2425.  
  2426. ihann, idbout, idsines (optional) - if non-zero, then
  2427. respectively: apply a hanning window to the input; convert the
  2428. output magnitudes to dB; display the windowed sinusoids used in
  2429. DFT filtering.  The default values are 0,0,0 (rectangular window,
  2430. magnitude output, no sinusoid display).  
  2431.  
  2432. PERFORMANCE 
  2433.  
  2434. octdown - put signal asig or ksig through iocts successive
  2435. applications of octave decimation and downsampling, and preserve
  2436. isamps down-sampled values in each octave.  Optionally display
  2437. the composite buffer every idisprd seconds.  
  2438.  
  2439. noctdft - generate a constant-Q, exponentially-spaced DFT across
  2440. all octaves of the multiply-downsampled input dsig.  Every iprd
  2441. seconds, each octave of dsig is optionally windowed (ihann
  2442. non-zero), filtered (using ifrqs parallel filters per octave,
  2443. exponentially spaced, and with frequency/bandwidth Q of iq), and
  2444. the output magnitudes optionally converted to dB (idbout
  2445. non-zero).  This unit produces a self-defining spectral datablock
  2446. wsig, whose characteristics are readable by any units that
  2447. receive it as input, and for which it becomes the template for
  2448. output.  The information used in producing this wsig (iprd,
  2449. iocts, ifrqs) is passed via the data block to all derivative
  2450. wsigs, and is thus available to subsequent spectral operators if
  2451. needed.
  2452.  
  2453. Example: 
  2454.  
  2455.      asig in                            ; get external audio
  2456.      dsamp     octdown   asig, 6, 180, 0          ; downsample in 6 octaves
  2457.      wsig1     noctdft   dsamp, .02, 12, 33, 0, 1, 1   ; and calc 72-point dft (dB)
  2458.  
  2459.      wsig specaddm  wsig1, wsig2[, imul2]
  2460.      wsig specdiff  wsigin
  2461.      wsig specscal  wsigin, ifscale, ifthresh
  2462.      wsig spechist  wsigin
  2463.      wsig specfilt  wsigin, ifhtim
  2464.  
  2465. INITIALIZATION 
  2466.  
  2467. imul2 (optional) - if non-zero, scale the wsig2 magnitudes before
  2468. adding.  The default value is 0.  
  2469.  
  2470. PERFORMANCE 
  2471.  
  2472. specaddm - do a weighted add of two input spectra.  For each
  2473. channel of the two input spectra, the two magnitudes are combined
  2474. and written to the output according to: magout = mag1in + mag2in
  2475. * imul2.  The operation is performed whenever the input wsig1 is
  2476. sensed to be new.  This unit will (at Initialization) verify the
  2477. consistency of the two spectra (equal size, equal period, equal
  2478. mag types).  
  2479.  
  2480. specdiff - find the positive difference values between
  2481. consecutive spectral frames.  At each new frame of wsigin, each
  2482. magnitude value is compared with its predecessor, and the
  2483. positive changes written to the output spectrum.  This unit is
  2484. useful as an energy onset detector.  
  2485.  
  2486. specscal - scale an input spectral datablock with spectral
  2487. envelopes.  Function tables ifthresh and ifscale are initially
  2488. sampled across the (logarithmic) frequency space of the input
  2489. spectrum; then each time a new input spectrum is sensed the
  2490. sampled values are used to scale each of its magnitude channels
  2491. as follows: if ifthresh is non-zero, each magnitude is reduced by
  2492. its corresponding table-value (to not less than zero); then each
  2493. magnitude is rescaled by the corresponding ifscale value, and the
  2494. resulting spectrum written to wsig.  
  2495.  
  2496. spechist - accumulate the values of successive spectral frames. 
  2497. At each new frame of wsigin, the accumulations-to-date in each
  2498. magnitude track are written to the output spectrum.  This unit
  2499. thus provides a running histogram of spectral distribution.  
  2500.  
  2501. specfilt - filter each channel of an input spectrum.  At each new
  2502. frame of wsigin, each magnitude value is injected into a
  2503. 1st-order lowpass recursive filter, whose half-time constant has
  2504. been initially set by sampling the ftable ifhtim across the
  2505. (logarithmic) frequency space of the input spectrum.  This unit
  2506. effectively applies a persistence factor to the data occurring in
  2507. each spectral channel, and is useful for simulating the energy
  2508. integration that occurs during auditory perception.  It may also
  2509. be used as a time-attenuated running histogram of the spectral
  2510. distribution.  
  2511.  
  2512.  
  2513. Example: 
  2514.  
  2515.      wsig2     specdiff       wsig1          ; sense onsets
  2516.      wsig3     specfilt       wsig2, 2       ; absorb slowly
  2517.                specdisp  wsig2, .1           ; & display both spectra
  2518.                specdisp  wsig3, .1
  2519.  
  2520.      koct      specptrk  wsig, inptls, irolloff, iodd[, interp, ifprd, iwtflg]
  2521.      ksum      specsum   wsig[, interp]
  2522.                specdisp  wsig, iprd[, iwtflg]
  2523.  
  2524. INITIALIZATION 
  2525.  
  2526. interp (optional) - if non-zero, interpolate the output signal
  2527. (koct or ksum).  The default value is 0 (repeat the signal value
  2528. between changes).  
  2529.  
  2530. ifprd (optional) - if non-zero, display the internally computed
  2531. fundamental spectrum.  The default value is 0 (no display).  
  2532.  
  2533. iwtflg (optional) - wait flag.  If non-zero, hold each display
  2534. until released by the user.  The default value is 0 (no wait).  
  2535.  
  2536. PERFORMANCE 
  2537.  
  2538. specptrk - estimate the pitch of the most prominent complex tone
  2539. in the spectrum.  At note initialization this unit creates a set
  2540. of inptls harmonically related partials (odd if iodd non-zero)
  2541. with amplitude rolloff to the fraction irolloff per octave. Then
  2542. at each new frame of wsig, the spectrum is cross-correlated with
  2543. this set, and the result at each point added to an internal copy
  2544. of the spectrum (optionally displayed).  A pitch is then
  2545. estimated, and the result is released in decimal octave form. 
  2546. Between frames, the output is either repeated or interpolated at
  2547. the K-rate.
  2548.  
  2549. specsum - sum the magnitudes across all channels of the spectrum. 
  2550. At each new frame of wsig, the magnitudes are summed and released
  2551. as a scalar ksum signal.  Between frames, the output is either
  2552. repeated or interpolated at the K-rate.  This unit produces a
  2553. k-signal summation of the magnitudes present in the spectral
  2554. data, and is thereby a running measure of its moment-to-moment
  2555. overall strength.  
  2556.  
  2557. specdisp - display the magnitude values of spectrum wsig every
  2558. iprd seconds (rounded to some integral number of wsig's
  2559. originating iprd).  
  2560.  
  2561.  
  2562. Example: 
  2563.  
  2564.      ksum specsum   wsig,  1            ; sum the spec bins, and ksmooth
  2565.           if        ksum < 2000   kgoto  zero     ; if sufficient amplitude
  2566.      koct specptrk       wsig                ;    pitch-track the signal
  2567.           kgoto          contin
  2568. zero:     koct =         0                   ; else output zero
  2569. contin:
  2570.  
  2571. SENSING & CONTROL 
  2572.  
  2573.      ktemp     tempest   kin, iprd, imindur, imemdur, ihp, ithresh, ihtim, ixfdbak, 
  2574.                          istartempo, ifn[, idisprd, itweek]
  2575.  
  2576. Estimate the tempo of beat patterns in a control signal.  
  2577.  
  2578. INITIALIZATION
  2579.  
  2580. iprd - period between analyses (in seconds).  Typically about .02
  2581. seconds.  
  2582.  
  2583. imindur - minimum duration (in seconds) to serve as a unit of
  2584. tempo.  Typically about .2 seconds.  
  2585.  
  2586. imemdur - duration (in seconds) of the kin short-term memory
  2587. buffer which will be scanned for periodic patterns.  Typically
  2588. about 3 seconds.  
  2589.  
  2590. ihp - half-power point (in cps) of a low-pass filter used to
  2591. smooth input kin prior to other processing.  This will tend to
  2592. suppress activity that moves much faster.  Typically 2 cps.  
  2593.  
  2594. ithresh - loudness threshold by which the low-passed kin is
  2595. center-clipped before being placed in the short-term buffer as
  2596. tempo-relevant data.  Typically at the noise floor of the
  2597. incoming data.  
  2598.  
  2599. ihtim - half-time (in seconds) of an internal forward-masking
  2600. filter that masks new kin data in the presence of recent, louder
  2601. data.  Typically about .005 seconds.  
  2602.  
  2603. ixfdbak - proportion of this unit's anticipated value to be mixed
  2604. with the incoming kin prior to all processing.  Typically about
  2605. .3.  
  2606.  
  2607. istartempo - initial tempo (in beats per minute).  Typically 60.  
  2608.  
  2609. ifn - table number of a stored function (drawn left-to-right) by
  2610. which the short-term memory data  is attenuated over time.  
  2611.  
  2612. idisprd (optional) - if non-zero, display the short-term past and
  2613. future buffers every idisprd seconds (normally a multiple of
  2614. iprd).  The default value is 0 (no display).  
  2615.  
  2616. itweek (optional) - fine-tune adjust this unit so that it is
  2617. stable when analyzing events controlled by its own output.  The
  2618. default value is 1 (no change).  
  2619.  
  2620. PERFORMANCE 
  2621.  
  2622. tempest examines kin for amplitude periodicity, and estimates a
  2623. current tempo.  The input is first low-pass filtered, then
  2624. center-clipped, and the residue placed in a short-term memory
  2625. buffer (attenuated over time) where it is analyzed for
  2626. periodicity using a form of autocorrelation.  The period,
  2627. expressed as a tempo in beats per minute, is output as ktemp. 
  2628. The period is also used internally to make predictions about
  2629. future amplitude patterns, and these are placed in a buffer
  2630. adjacent to that of the input.  The two adjacent buffers can be
  2631. periodically displayed, and the predicted values optionally mixed
  2632. with the incoming signal to simulate expectation.  
  2633.  
  2634. This unit is useful for sensing the metric implications of any
  2635. k-signal (e.g- the RMS of an audio signal, or the second
  2636. derivative of a conducting gesture), before sending to a tempo
  2637. statement.  
  2638.  
  2639.  
  2640. Example:
  2641.  
  2642. ksum specsum   wsignal, 1                         ; sum the amps
  2643. of a spectrum
  2644. ktemp     tempest   ksum, .02, .1, 3, 2, 800, .005, 0, 60, 4, .1, .995 ; and look for beats
  2645.  
  2646.          kx, ky     xyin      iprd, ixmin, ixmax, iymin, iymax[, ixinit, iyinit] 
  2647.           tempo     ktempo, istartempo 
  2648.  
  2649. Sense the cursor position in an input window.  Apply tempo
  2650. control to an uninterpreted score.  
  2651.  
  2652. INITIALIZATION 
  2653.  
  2654. iprd - period of cursor sensing (in seconds).  Typically .1
  2655. seconds.  
  2656.  
  2657. xmin, xmax, ymin, ymax - edge values for the x-y coordinates of a
  2658. cursor in the input window.  
  2659.  
  2660. ixinit, iyinit (optional) - initial x-y coordinates reported; the
  2661. default values are 0,0.  If these values are not within the given
  2662. min-max range, they will be coerced into that range.  
  2663.  
  2664. istartempo - initial tempo (in beats per minute).  Typically 60.  
  2665.  
  2666. PERFORMANCE 
  2667.  
  2668. xyin samples the cursor x-y position in an input window every
  2669. iprd seconds.  Output values are repeated (not interpolated) at
  2670. the K-rate, and remain fixed until a new change is registered in
  2671. the window.  There may be any number of input windows.  This unit
  2672. is useful for Realtime control,  but continuous motion should be
  2673. avoided if iprd is unusually small.  
  2674.  
  2675. tempo allows the performance speed of Csound scored events to be
  2676. controlled from within an orchestra.  It operates only in the
  2677. presence of the csound -t flag.  When that flag is set, scored
  2678. events will be performed from their uninterpreted p2 and p3
  2679. (beat) parameters, initially at the given command-line tempo. 
  2680. When a tempo statement is activated in any instrument (ktempo >
  2681. 0.), the operating tempo will be adjusted to ktempo beats per
  2682. minute.  There may be any number of tempo statements in an
  2683. orchestra, but coincident activation is best avoided.  
  2684.  
  2685.  
  2686. Example: 
  2687.  
  2688.           kx,ky     xyin .05, 30, 0, 120, 0, 75   ; sample the cursor
  2689.           tempo     kx, 75             ; and control the tempo of performance
  2690.  
  2691. SOUND INPUT & OUTPUT
  2692.  
  2693. a1        in 
  2694. a1, a2         ins 
  2695. a1, a2, a3, a4 inq 
  2696. a1        soundin   ifilcod[, iskptim][, iformat] 
  2697. a1, a2         soundin   ifilcod[, iskptim][, iformat] 
  2698. a1, a2, a3, a4 soundin   ifilcod[, iskptim][, iformat] 
  2699.           out       asig 
  2700.           outs1     asig 
  2701.           outs2     asig 
  2702.           outs      asig1, asig2
  2703.           outq1     asig 
  2704.           outq2     asig
  2705.           outq3     asig 
  2706.           outq4     asig 
  2707.           outq      asig1, asig2, asig3, asig4 
  2708.  
  2709. These units read/write audio data from/to an external device or
  2710. stream.  
  2711.  
  2712. INITIALIZATION
  2713.  
  2714. filcod - integer or character-string denoting the source
  2715. soundfile name.  An integer denotes the file soundin.filcod ;  a
  2716. character-string (in double quotes, spaces permitted) gives the
  2717. filename itself, optionally a full pathname.  If not a full path,
  2718. the named file is sought first in the current directory, then in
  2719. that given by the environment variable SSDIR (if defined) then by
  2720. SFDIR.  See also GEN01.
  2721.  
  2722. iskptim (optional) - time in seconds of input sound to be
  2723. skipped.  The default value is 0.  
  2724.  
  2725. iformat (optional) - specifies the audio data file format (1 =
  2726. 8-bit signed char, 2 = 8-bit A-law bytes, 3 = 8-bit U-law bytes,
  2727. 4 = 16-bit short integers, 5 = 32bit long integers, 6 = 32-bit
  2728. floats).  If iformat = 0 it is taken from the soundfile header,
  2729. and if no header from the csound -o command flag.  The default
  2730. value is 0.  
  2731.  
  2732. PERFORMANCE 
  2733.  
  2734. in, ins, inq - copy the current values from the standard audio
  2735. input buffer.  If the command-line flag -i is set, sound is read
  2736. continuously from the audio input stream (e.g. stdin or a
  2737. soundfile) into an internal buffer.  Any number of these units
  2738. can read freely from this buffer.  
  2739.  
  2740. soundin is functionally an audio generator that derives its
  2741. signal from a pre-existing file.  The number of channels read in
  2742. is set by the number of result cells, a1, a2, etc.  A soundin
  2743. unit opens this file whenever the host instrument is initialized,
  2744. then closes it again each time the instrument is turned off. 
  2745. There can be any number of soundin units within a single
  2746. instrument or orchestra; also, two or more of them can read
  2747. simultaneously from the same external file.  
  2748.  
  2749. out, outs, outq send audio samples to an accumulating output
  2750. buffer (created at the beginning of performance) which serves to
  2751. collect the output of all active instruments before the sound is
  2752. written to disk.  There can be any number of these output units
  2753. in an instrument.  The type (mono, stereo, or quad) must agree
  2754. with nchnls, but units can be chosen to direct sound to any
  2755. particular channel: outs1 sends to stereo channel 1, outq3 to
  2756. quad channel 3, etc.  
  2757.  
  2758. a1, a2, a3, a4 pan       asig, kx, ky, ifn[, imode][, ioffset] 
  2759.  
  2760. Distribute an audio signal amongst four channels with
  2761. localization control.  
  2762.  
  2763. INITIALIZATION 
  2764.  
  2765. ifn - function table number of a stored pattern describing the
  2766. amplitude growth in a speaker channel as sound moves towards it
  2767. from an adjacent speaker.  Requires extended guard-point.  
  2768.  
  2769. imode (optional) - mode of the kx, ky position values.  0
  2770. signifies raw index mode, 1 means the inputs are normalized (0 -
  2771. 1).  The default value is 0.  
  2772.  
  2773. ioffset (optional) - offset indicator for kx, ky.  0 infers the
  2774. origin to be at channel 3 (left rear); 1 requests an axis shift
  2775. to the quadraphonic center.  The default value is 0.  
  2776.  
  2777. PERFORMANCE 
  2778.  
  2779. pan takes an input signal asig and distributes it amongst four
  2780. outputs (essentially quad speakers) according to the controls kx
  2781. and ky.  For normalized input (mode=1) and no offset, the four
  2782. output locations are in order: left-front at (0,1), right-front
  2783. at (1,1), left-rear at the origin (0,0), and right-rear at (1,0). 
  2784. In the notation (kx, ky), the coordinates kx and ky, each ranging
  2785. 0 - 1, thus control the 'rightness' and 'forwardness' of a sound
  2786. location.  
  2787.  
  2788. Movement between speakers is by amplitude variation, controlled
  2789. by the stored function table ifn.  As kx goes from 0 to 1, the
  2790. strength of the right-hand signals will grow from the left-most
  2791. table value to the right-most, while that of the left-hand
  2792. signals will progress from the right-most table value to the
  2793. left-most.  For a simple linear pan, the table might contain the
  2794. linear function 0 - 1.  A more correct pan that maintains
  2795. constant power would be obtained by storing the first quadrant of
  2796. a sinusoid.  Since pan will scale and truncate kx and ky in
  2797. simple table lookup, a medium-large table (say 8193) should be
  2798. used.  
  2799.  
  2800. kx, ky values are not restricted to 0 - 1.  A circular motion
  2801. passing through all four speakers (enscribed) would have a
  2802. diameter of root 2, and might be defined by a circle of radius R
  2803. = root 1/2 with center at (.5,.5).  kx, ky would then come from
  2804. Rcos(angle), Rsin(angle), with an implicit origin at (.5,.5)
  2805. (i.e.  ioffset = 1).  Unscaled raw values operate similarly. 
  2806. Sounds can thus be located anywhere in the polar or cartesian
  2807. plane; points lying outside the speaker square are projected
  2808. correctly onto the square's perimeter as for a listener at the
  2809. center.  
  2810.  
  2811.  
  2812. Example:
  2813.                instr     1
  2814.      k1   phasor  1/p3                  ; fraction of circle
  2815.      k2   tablei    k1, 1, 1            ; sin of angle (sinusoid in f1)
  2816.      k3   tablei    k1, 1, 1, .25, 1    ; cos of angle (sin offset 1/4 circle)
  2817.      a1   oscili    10000,440, 1        ; audio signal..
  2818. a1,a2,a3,a4    pan  a1, k2/2, k3/2, 2, 1, 1  ; sent in a circle (f2=1st quad sin)
  2819.           outq a1, a2, a3, a4
  2820.           endin
  2821.  
  2822. SIGNAL DISPLAY
  2823.  
  2824.           print          iarg[, iarg,...] 
  2825.           display   xsig, iprd[, iwtflg] 
  2826.           dispfft   xsig, iprd, iwsiz[, iwtyp][, idbouti][, iwtflg] 
  2827.  
  2828. These units will print orchestra Init-values, or produce graphic
  2829. display of orchestra control signals and audio signals.  Uses X11
  2830. windows if enabled, else (or if -g flag is set) displays are
  2831. approximated in ascii characters.  
  2832.  
  2833. INITlALIZATION 
  2834.  
  2835. iprd - the period of display in seconds.  
  2836.  
  2837. iwsiz - size of the input window in samples.  A window of iwsiz
  2838. points will produce a Fourier transform of iwsiz/2 points, spread
  2839. linearly in frequency from 0 to sr/2.  iwsiz must be a power of
  2840. 2.  The windows are permitted to overlap.  
  2841.  
  2842. iwtyp (optional) - window type.  0 = rectangular, 1 = hanning. 
  2843. The default value is 0 (rectangular).  
  2844.  
  2845. idbout (optional) - units of output for the Fourier coefficients. 
  2846. 0 = magnitude, 1 = decibels.  The default is 0 (magnitude).  
  2847.  
  2848. iwtflg (optional) - wait flag.  If non-zero, each display is held
  2849. until released by the user.  The default value is 0 (no wait).  
  2850.  
  2851. PERFORMANCE
  2852.  
  2853. print - print the current value of the I-time arguments (or
  2854. expressions) iarg at every I-pass through the instrument.  
  2855.  
  2856. display - display the audio or control signal xsig every iprd
  2857. seconds, as an amplitude vs. time graph.  
  2858.  
  2859. dispfft - display the Fourier Transform of an audio or control
  2860. signal (asig or ksig) every iprd seconds using the Fast Fourier
  2861. Transform method.  
  2862.  
  2863.  
  2864. Example: 
  2865.  
  2866.      k1   envlpx    l, .03, p3, .05, l, .5, .0l   ; generate a note envelope
  2867.           display   k1, p3                   ; and display entire shape 
  2868.  
  2869.  
  2870. 3.  THE STANDARD NUMERIC SCORE
  2871.  
  2872.  
  2873. A score is a data file that provides information to an orchestra
  2874. about its performance.  Like an orchestra file, a score file is
  2875. made up of statements in a known format.  The Csound orchestra
  2876. expects to be handed a score comprised mainly of ascii numeric
  2877. characters.  Although most users will prefer a higher level score
  2878. language such as provided by Cscore, Scot, or another
  2879. score-generating program, each resulting score must eventually
  2880. appear in the format expected by the orchestra.  A Standard
  2881. Numeric Score can be created and edited directly by the beginner
  2882. using standard text editors; indeed, some users continue to
  2883. prefer it.  The purpose of this section is to describe this
  2884. format in detail.  
  2885.  
  2886. The basic format of a standard numeric score statement is: 
  2887.  
  2888.            opcode p1 p2 p3 p4...             ;comments 
  2889.  
  2890. The opcode is a single character, always alphabetic.  Legal
  2891. opcodes are f, i, a, t, s, and e, the meanings of which are
  2892. described in the following pages.  The opcode is normally the
  2893. first character of a line; leading spaces or tabs will be
  2894. ignored.  Spaces or tabs between the opcode and p1 are optional.  
  2895.  
  2896. p1, p2, p3, etc...  are parameter fields (pfields).  Each
  2897. contains a floating point number comprised of an optional sign,
  2898. digits, and an optional decimal point.  Expressions are not
  2899. permitted in Standard Score files.  pfields are separated from
  2900. each other by one or more spaces or tabs, all but one space of
  2901. which will be ignored.  
  2902.  
  2903. Continuation lines are permitted.  If the first printing
  2904. character of a new scoreline is not an opcode, that line will be
  2905. regarded as a continuation of the pfields from the previous
  2906. scoreline.  
  2907.  
  2908. Comments are optional and are for the purpose of permitting the
  2909. user to document his score file.  Comments always begin with a
  2910. semicolon (;) and extend to the end of the line.  Comments will
  2911. not affect the pfield continuation feature.  
  2912.  
  2913. Blank lines or comment-only lines are legal (and will be
  2914. ignored).  
  2915.  
  2916. Preprocessing of Standard Scores
  2917.  
  2918. A Score (a collection of score statements) is divided into
  2919. time-ordered sections by the s statement.  Before being read by
  2920. the orchestra, a score is preprocessed one section at a time. 
  2921. Each section is normally processed by 3 routines: Carry, Tempo,
  2922. and Sort.  
  2923.  
  2924. 1.  Carry - within a group of consecutive i statements whose p1
  2925. whole numbers correspond, any pfield left empty will take its
  2926. value from the same pfield of the preceding statement.  An empty
  2927. pfield can be denoted by a single point (.) delimited by spaces. 
  2928. No point is required after the last nonempty pfield.  The output
  2929. of Carry preprocessing will show the carried values explicitly. 
  2930. The Carry Feature is not affected by intervening comments or
  2931. blank lines; it is turned off only by a non-i statement or by an
  2932. i statement with unlike p1 whole number.  
  2933.  
  2934. An additional feature is available for p2 alone.  The symbol + in
  2935. p2 will be given the value of p2 + p3 from the preceding i
  2936. statement.  This enables note action times to be automatically
  2937. determined from the sum of preceding durations.  The + symbol can
  2938. itself be carried.  It is legal only in p2.  
  2939.  
  2940.  
  2941. E.g.:     the statements 
  2942.                i1   0    .5        100         
  2943.                i .  +                   
  2944.                i
  2945.      will result in           
  2946.                i1   0         .5        100
  2947.                i1   .5   .5   100
  2948.                i1   1         .5        100 
  2949.  
  2950. The Carry feature should be used liberally.  Its use, especially
  2951. in large scores, can greatly reduce input typing and will
  2952. simplify later changes.  
  2953.  
  2954. 2.  Tempo - this operation time warps a score section according
  2955. to the information in a t statement.  The tempo operation
  2956. converts p2 (and, for i statements, p3) from original beats into
  2957. real seconds, since those are the units required by the
  2958. orchestra.  After time warping, score files will be seen to have
  2959. orchestra-readable format demonstrated by the following: 
  2960.  
  2961.           i p1 p2beats p2seconds p3beats p3seconds p4 p5 ....  
  2962.  
  2963. 3.  Sort - this routine sorts all action-time statements into
  2964. chronological order by p2 value.  It also sorts coincident events
  2965. into precedence order.  Whenever an f statement and an i
  2966. statement have the same p2 value, the f statement will precede. 
  2967. Whenever two or more i statements have the same p2 value, they
  2968. will be sorted into ascending p1 value order.  If they also have
  2969. the same p1 value, they will be sorted into ascending p3 value
  2970. order.  Score sorting is done section by section (see s
  2971. statement).  Automatic sorting implies that score statements may
  2972. appear in any order within a section.  
  2973.  
  2974. N.B.  The operations Carry, Tempo and Sort are combined in a
  2975. 3-phase single pass over a score file, to produce a new file in
  2976. orchestra-readable format (see the Tempo example).  Processing
  2977. can be invoked either explicitly by the scsort command, or
  2978. implicitly by csound which processes the score before calling the
  2979. orchestra.  Source-format files and orchestra-readable files are
  2980. both in ascii character form, and may be either perused or
  2981. further modified by standard text editors.  Userwritten routines
  2982. can be used to modify score files before or after the above
  2983. processes, provided the final orchestra-readable statement format
  2984. is not violated.  Sections of different formats can be
  2985. sequentially batched; and sections of like format can be merged
  2986. for automatic sorting.  
  2987.  
  2988. Next-P and Previous-P Symbols
  2989.  
  2990. At the close of any of the above operations, three additional
  2991. score features are interpreted during file writeout: next-p,
  2992. previous-p, and ramping.  
  2993.  
  2994. i statement pfields containing the symbols npx or ppx (where x is
  2995. some integer) will be replaced by the appropriate pfield value
  2996. found on the next i statement (or previous i statement) that has
  2997. the same p1.  For example, the symbol np7 will be replaced by the
  2998. value found in p7 of the next note that is to be played by this
  2999. instrument.  np and pp symbols are recursive and can reference
  3000. other np and pp symbols which can reference others, etc. 
  3001. References must eventually terminate in a real number or a ramp
  3002. symbol (see below).  Closed loop references should be avoided. 
  3003. np and pp symbols are illegal in p1,p2 and p3 (although they may
  3004. reference these).  np and pp symbols may be Carried.  np and pp
  3005. references cannot cross a Section boundary.  Any forward or
  3006. backward reference to a non-existent note-statement will be given
  3007. the value zero.  
  3008.  
  3009.  
  3010. E.g.:     the statements
  3011.                i1   0    1    10   np4  pp5 
  3012.                i1   1    1    20
  3013.                i1   1    1    30
  3014.      will result in
  3015.                i1   0    1    10   20   0 
  3016.                i1   1    1    20   30   20 
  3017.                i1   2    1    30   0    30 
  3018.  
  3019. np and pp symbols can provide an instrument with contextual
  3020. knowledge of the score, enabling it to glissando or crescendo,
  3021. for instance, toward the pitch or dynamic of some future event
  3022. (which may or may not be immediately adjacent).  Note that while
  3023. the Carry feature will propagate np and pp through unsorted
  3024. statements, the operation that interprets these symbols is acting
  3025. on a time-warped and fully sorted version of the score.  
  3026.  
  3027. Ramping
  3028.  
  3029. i statement pfields containing the symbol < will be replaced by
  3030. values derived from linear interpolation of a time-based ramp. 
  3031. Ramps are anchored at each end by the first real number found in
  3032. the same pfield of a preceding and following note played by the
  3033. same instrument.
  3034.  
  3035. E.g.:     the statements
  3036.                i1   0    1    100
  3037.                i1   1    1    <
  3038.                i1   2    1    <
  3039.                i1   3    1    400
  3040.                i1   4    1    <
  3041.                i1   5    1    0
  3042.      will result in
  3043.                i1   0    1    100 
  3044.                i1   1    1    200
  3045.                i1   2    1    300
  3046.                i1   3    1    400
  3047.                i1   4    1    200
  3048.                i1   5    1    0
  3049.  
  3050. Ramps cannot cross a Section boundary.  Ramps cannot be anchored
  3051. by an np or pp symbol (although they may be referenced by these). 
  3052. Ramp symbols are illegal in p1, p2 and p3.  Ramp symbols may be
  3053. Carried.  Note, however, that while the Carry feature will
  3054. propagate ramp symbols through unsorted statements, the operation
  3055. that interprets these symbols is acting on a time-warped and
  3056. fully sorted version of the score.  In fact, time-based linear
  3057. interpolation is based on warped score-time, so that a ramp which
  3058. spans a group of accelerating notes will remain linear with
  3059. respect to strict chronological time.  
  3060.  
  3061. F STATEMENT (or  FUNCTION TABLE STATEMENT) 
  3062.  
  3063.      f  p1  p2  p3  p4 ...  
  3064.  
  3065. This causes a GEN subroutine to place values in a stored function
  3066. table for use by instruments.  
  3067.  
  3068.  
  3069. PFIELDS
  3070.  
  3071.      p1   Table number (from 1 to 200) by which the stored function will be known.
  3072.           A negative number requests that the table be destroyed.  
  3073.  
  3074.      p2   Action time of function generation (or destruction) in beats.
  3075.  
  3076.      p3   Size of function table (i.e.  number of points).
  3077.           Must be a power of 2, or a power-of-2 plus 1 (see below).
  3078.           Maximum table size is 16777216 (2**24) points.
  3079.  
  3080.      p4   Number of the GEN routine to be called (see GEN ROUTINES).     
  3081.           A negative value will cause rescaling to be omitted.
  3082.  
  3083.      p5   |
  3084.      p6   |   Parameters whose meaning is determined by the particular GEN routine.  
  3085.      .    |
  3086.      .    |
  3087.  
  3088.  
  3089. SPECIAL CONSIDERATIONS 
  3090.  
  3091. Function tables are arrays of floating-point values.  Arrays can
  3092. be of any length in powers of 2; space allocation always provides
  3093. for 2**n points plus an additional guard point.  The guard point
  3094. value, used during interpolated lookup, can be automatically set
  3095. to reflect the table's purpose: If size is an exact power of 2,
  3096. the guard point will be a copy of the first point; this is
  3097. appropriate for interpolated wrap-around lookup as in oscili,
  3098. etc., and should even be used for non-interpolating oscil for
  3099. safe consistency.  If size is set to 2**n + 1, the guard point
  3100. value automatically extends the contour of table values; this is
  3101. appropriate for single-scan functions such in envlpx, oscil1,
  3102. oscil1i, etc.  
  3103.  
  3104. Table space is allocated in primary memory, along with instrument
  3105. data space.  The maximum table number has a soft limit of 200; 
  3106. this can be extended if required.  
  3107.  
  3108. An existing function table can be removed by an f statement
  3109. containing a negative p1 and an appropriate action time.  A
  3110. function table can also be removed by the generation of another
  3111. table with the same p1.  Functions are not automatically erased
  3112. at the end of a score section.  
  3113.  
  3114. p2 action time is treated in the same way as in i statements with
  3115. respect to sorting and modification by t statements.  If an f
  3116. statement and an i statement have the same p2, the sorter gives
  3117. the f statement precedence so that the function table will be
  3118. available during note initialization.  
  3119.  
  3120. An f 0 statement (zero p1, positive p2) may be used to create an
  3121. action time with no associated action.  Such time markers are
  3122. useful for padding out a score section (see s statement).  
  3123.  
  3124. I STATEMENT (INSTRUMENT or NOTE STATEMENT) 
  3125.  
  3126.      i  p1  p2  p3  p4  ...  
  3127.  
  3128. This statement calls for an instrument to be made active at a
  3129. specific time and for a certain duration.  The parameter field
  3130. values are passed to that instrument prior to its initialization,
  3131. and remain valid throughout its Performance.  
  3132.  
  3133. PFIELDS
  3134.  
  3135.      p1   Instrument number (from 1 to 200), usually a non-negative integer.
  3136.           An optional fractional part can provide an additional tag for specifying
  3137.           ties between particular notes of consecutive clusters.  A negative p1
  3138.           (including tag) can be used to turn off a particular `held' note.
  3139.  
  3140.      p2   Starting time in arbitrary units called beats.  
  3141.  
  3142.      p3        Duration time in beats (usually positive).  A negative value will initiate a
  3143.           held note (see also ihold).  A zero value will invoke an initialization pass
  3144.           without performance (see also instr).  
  3145.  
  3146.      p4   |
  3147.      p5   |   Parameters whose significance is determined by the instrument.  
  3148.      .    |
  3149.      .    |
  3150.  
  3151. SPECIAL CONSIDERATIONS 
  3152.  
  3153. Beats are evaluated as seconds, unless there is a t statement in
  3154. this score section or a -t flag in the command line.  
  3155.  
  3156. Starting or action times are relative to the beginning of a
  3157. section (see s statement), which is assigned time 0.  
  3158.  
  3159. Note statements within a section may be placed in any order. 
  3160. Before being sent to an orchestra, unordered score statements
  3161. must first be processed by Sorter, which will reorder them by
  3162. ascending p2 value.  Notes with the same p2 value will be ordered
  3163. by ascending p1; if the same p1, then by ascending p3.  
  3164.  
  3165. Notes may be stacked, i.e., a single instrument can perform any
  3166. number of notes simultaneously.  (The necessary copies of the
  3167. instrument's data space will be allocated dynamically by the
  3168. orchestra loader.)  Each note will normally turn off when its p3
  3169. duration has expired, or on receipt of a MIDI noteoff signal.  An
  3170. instrument can modify its own duration either by changing its p3
  3171. value during note initialization, or by prolonging itself through
  3172. the action of a linenr unit.
  3173.  
  3174. An instrument may be turned on and left to perform indefinitely
  3175. either by giving it a negative p3 or by including an ihold in its
  3176. I-time code.  If a held note is active, an i statement with
  3177. matching p1 will not cause a new allocation but will take over
  3178. the data space of the held note.  The new pfields (including p3)
  3179. will now be in effect, and an I-time pass will be executed in
  3180. which the units can either be newly initialized or allowed to
  3181. continue as required for a tied note (see tigoto).  A held note
  3182. may be succeeded either by another held note or by a note of
  3183. finite duration.  A held note will continue to perform across
  3184. section endings (see s statement).  It is halted only by turnoff
  3185. or by an i statement with negative matching p1 or by an e
  3186. statement.  
  3187.  
  3188. A STATEMENT (or ADVANCE STATEMENT) 
  3189.  
  3190.      a  p1  p2  p3 
  3191.  
  3192. This causes score time to be advanced by a specified amount
  3193. without producing sound samples.  
  3194.  
  3195.  
  3196. PFIELDS
  3197.  
  3198.      p1   carries no meaning.  Usually zero 
  3199.      p2   Action time, in beats, at which advance is to begin.  
  3200.      p3   Durational span (distance in beats) of time advance.  
  3201.  
  3202.      p4   |
  3203.      p5   |    These carry no meaning.  
  3204.      .
  3205.      .
  3206.  
  3207. SPECIAL CONSIDERATIONS 
  3208.  
  3209. This statement allows the beat count within a score section to be
  3210. advanced without generating intervening sound samples.  This can
  3211. be of use when a score section is incomplete (the beginning or
  3212. middle is missing) and the user does not wish to generate and
  3213. listen to a lot of silence.  
  3214.  
  3215. p2 action time and p3 distance are treated as in i statements,
  3216. with respect to sorting and modification by t statements.  
  3217.  
  3218. An a statement will be temporarily inserted in the score by the
  3219. Score Extract feature when the extracted segment begins later
  3220. than the start of a Section.  The purpose of this is to preserve
  3221. the beat count and time count of the original score for the
  3222. benefit of the peak amplitude messages which are reported on the
  3223. user console.  
  3224.  
  3225. Whenever an a statement is encountered by a performing orchestra,
  3226. its presence and effect will be reported on the user's console.  
  3227.  
  3228. T STATEMENT (TEMPO STATEMENT) 
  3229.  
  3230.      t  p1  p2  p3  p4  .....  (unlimited) 
  3231.  
  3232. This statement sets the tempo and specifies the accelerations and
  3233. decelerations for the current section.  This is done by
  3234. converting beats into seconds.  
  3235.  
  3236.  
  3237. PFIELDS
  3238.  
  3239.      p1             must be zero 
  3240.      p2             initial tempo in beats per minute 
  3241.      p3, p5, p7, ...     times in beats (in non-decreasing order) 
  3242.      p4, p6, p8, ...     tempi for the referenced beat times 
  3243.  
  3244.  
  3245. SPECIAL CONSIDERATIONS 
  3246.  
  3247. Time and Tempo-for-that-time are given as ordered couples that
  3248. define points on a "tempo vs time" graph.  (The time-axis here is
  3249. in beats so is not necessarily linear.) The beat-rate of a
  3250. Section can be thought of as a movement from point to point on
  3251. that graph: motion between two points of equal height signifies
  3252. constant tempo, while motion between two points of unequal height
  3253. will cause an accelarando or ritardando accordingly.  The graph
  3254. can contain discontinuities: two points given equal times but
  3255. different tempi will cause an immediate tempo change.  
  3256.  
  3257. Motion between different tempos over non-zero time is inverse
  3258. linear.  That is, an accelerando between two tempos M1 and M2
  3259. proceeds by linear interpolation of the single-beat durations
  3260. from 60/M1 to 60/M2.  
  3261.  
  3262. The first tempo given must be for beat 0.  
  3263.  
  3264. A tempo, once assigned, will remain in effect from that
  3265. time-point unless influenced by a succeeding tempo, i.e.  the
  3266. last specified tempo will be held to the end of the section.  
  3267.  
  3268. A t statement applies only to the score section in which it
  3269. appears.  Only one t statement is meaningful in a section; it can
  3270. be placed anywhere within that section.  If a score section
  3271. contains no t statement, then beats are interpreted as seconds
  3272. (i.e. with an implicit t 0 60 statement).
  3273.  
  3274. N.B.  If the csound command includes a -t flag, the interpreted
  3275. tempo of all score t statements will be overridden by the
  3276. command-line tempo. 
  3277.  
  3278. S STATEMENT 
  3279.  
  3280.      s  anything 
  3281.  
  3282. The s statement marks the end of a section.  
  3283.  
  3284.  
  3285. PFIELDS
  3286.  
  3287. All pfields are ignored.  
  3288.  
  3289.  
  3290. SPECIAL CONSIDERATIONS 
  3291.  
  3292. Sorting of the i, f and a statements by action time is done
  3293. section by section.  
  3294.  
  3295. Time warping for the t statement is done section by section.  
  3296.  
  3297. All action times within a section are relative to its beginning. 
  3298. A section statement establishes a new relative time of 0, but has
  3299. no other reinitializing effects (e.g. stored function tables are
  3300. preserved across section boundaries).  
  3301.  
  3302. A section is considered complete when all action times and finite
  3303. durations have been satisfied (i.e., the "length" of a section is
  3304. determined by the last occurring action or turn-off).  A section
  3305. can be extended by the use of an f 0 statement.  
  3306.  
  3307. A section ending automatically invokes a Purge of inactive
  3308. instrument and data spaces.  
  3309.  
  3310. N.B. Since score statements are processed section by section, the
  3311. amount of memory required depends on the maximum number of score
  3312. statements in a section.  Memory allocation is dynamic, 
  3313. and the user will be informed as extra memory blocks are
  3314. requested during score processing.  
  3315.  
  3316. For the end of the final section of a score, the s statement is
  3317. optional; the e statement may be used instead.  
  3318.  
  3319. E STATEMENT 
  3320.  
  3321.      e anything 
  3322.  
  3323. This statement may be used to mark the end of the last section of
  3324. the score.  
  3325.  
  3326.  
  3327. PFIELDS
  3328.  
  3329. All pfields are ignored.
  3330.  
  3331.  
  3332. SPECIAL CONSIDERATIONS 
  3333.  
  3334. The e statement is contextually identical to an s statement. 
  3335. Additionally, the e statement terminates all signal generation
  3336. (including indefinite performance) and closes all input and
  3337. output files.  
  3338.  
  3339. If an e statement occurs before the end of a score, all
  3340. subsequent score lines will be ignored.  
  3341.  
  3342. The e statement is optional in a score file yet to be sorted.  If
  3343. a score file has no e statement, then Sort processing will supply
  3344. one.  
  3345.  
  3346. 4.  GEN ROUTINES
  3347.  
  3348.  
  3349. The GEN subroutines are function-drawing procedures called by f
  3350. statements to construct stored wavetables.  They are available
  3351. throughout orchestra performance, and can be invoked at any point
  3352. in the score as given by p2.  p1 assigns a table number, and p3
  3353. the table size (see f statement).  p4 specifies the GEN routine
  3354. to be called; each GEN routine will assign special meaning to the
  3355. pfield values that follow.  
  3356.  
  3357.  
  3358. GEN01 
  3359.  
  3360. This subroutine transfers data from a soundfile into a function
  3361. table.  
  3362.  
  3363.      f  #  time  size  1  filcod  skiptime  format 
  3364.  
  3365. size - number of points in the table.  Ordinarily a power of 2 or
  3366. a power-of-2 plus 1 (see f statement);  the maximum tablesize is
  3367. 16777216 (2**24) points.  If the source soundfile is of type
  3368. AIFF, allocation of table memory can be deferred by setting this
  3369. parameter to 0;  the size allocated is then the number of points
  3370. in the file (probably not a power-of-2), and the table is not
  3371. usable by normal oscillators, but it is usable by a loscil unit. 
  3372. An AIFF source can also be mono or stereo.
  3373.  
  3374. filcod - integer or character-string denoting the source
  3375. soundfile name.  An integer denotes the file soundin.filcod ;  a
  3376. character-string (in double quotes, spaces permitted) gives the
  3377. filename itself, optionally a full pathname.  If not a full path,
  3378. the file is sought first in the current directory, then in that
  3379. given by the environment variable SSDIR (if defined) then by
  3380. SFDIR.  See also soundin.
  3381.  
  3382. skiptime - begin reading at skiptime seconds into the file.
  3383.  
  3384. format  - specifies the audio data-file format: 
  3385.  
  3386.           1 - 8-bit signed character    4 - 16-bit short integers 
  3387.           2 - 8-bit A-law bytes         5 - 32-bit long integers 
  3388.           3 - 8-bit U-law bytes         6 - 32-bit floats
  3389.  
  3390. If format = 0 the sample format is taken from the soundfile
  3391. header, or by default from the csound -o command flag.
  3392.  
  3393. Reading stops at end-of-file or when the table is full.  Table
  3394. locations not filled will contain zeros.  
  3395.  
  3396. Note: 
  3397.  
  3398. If p4 is positive, the table will be post-normalized (rescaled to
  3399. a maximum absolute value of 1 after generation).  A negative p4
  3400. will cause rescaling to be skipped.  
  3401.  
  3402. Examples: 
  3403.  
  3404.      f   1  0  8192  1  23  0  4
  3405.      f   2  0  0  -1  "trumpet  A#5"  0  4
  3406.  
  3407. The tables are filled from 2 files, "soundin.23" and "trumpet
  3408. A#5", expected in SSDIR or SFDIR.  The first table is
  3409. pre-allocated;  the second is allocated dynamically, and its
  3410. rescaling is inhibited.  
  3411.  
  3412.  
  3413. GEN02 
  3414.  
  3415. This subroutine transfers data from immediate pfields into a
  3416. function table.  
  3417.  
  3418.      f  #  time  size  2  v1  v2  v3  .  .  .  
  3419.  
  3420. size - number of points in the table.  Must be a power of 2 or a
  3421. power-of-2 plus 1 (see f statement).  The maximum tablesize is
  3422. 16777216 (2**24) points.  
  3423.  
  3424. v1, v2, v3, ... - values to be copied directly into the table
  3425. space.  The number of values is limited by the compile-time
  3426. variable PMAX, which controls the maximum pfields (currently
  3427. 150).  The values copied may include the table guard point;  any
  3428. table locations not filled will contain zeros.  
  3429.  
  3430. Note: 
  3431.  
  3432. If p4 is positive, the table will be post-normalized (rescaled to
  3433. a maximum absolute value of 1 after generation).  A negative p4
  3434. will cause rescaling to be skipped.  
  3435.  
  3436. Example: 
  3437.  
  3438.      f   1  0  16  -2  0  1  2  3  4  5  6  7  8  9  10  11  0 
  3439.  
  3440. This calls upon GEN02 to place 12 values plus an explicit
  3441. wrap-around guard value into a table of size next-highest power
  3442. of 2.  Rescaling is inhibited.  
  3443.  
  3444.  
  3445. GEN03 
  3446.  
  3447. This subroutine generates a stored function table by evaluating a
  3448. polynomial in x over a fixed inter- val and with specified
  3449. coefficients.  
  3450.  
  3451.  
  3452.      f  #  time  size  3  xval1  xval2  c0  c1  c2  .  .  .  cn 
  3453.  
  3454.  
  3455. size - number of points in the table.  Must be a power of 2 or a
  3456. power-of-2 plus 1 (see f statement).  
  3457.  
  3458. xval1, xval2 - left and right values of the x interval over which
  3459. the polynomial is defined (xval1 < xval2).  These will produce
  3460. the 1st stored value and the (power-of-2 plus l)th stored value
  3461. respectively in the generated function table.  
  3462.  
  3463. c0, c1, c2,  ...  cn  - coefficients of the nth-order polynomial 
  3464.  
  3465.                              c0 + c1x + c2x2 + .  .  .  + cnxn
  3466.  
  3467.  
  3468. Coefficients may be positive or negative real numbers; a zero
  3469. denotes a missing term in the polynomial.  The coefficient list
  3470. begins in p7, providing a current upper limit of 144 terms.  
  3471.  
  3472.  
  3473. Note: 
  3474.  
  3475. The defined segment [fn(xval1),fn(xval2)] is evenly distributed. 
  3476. Thus a 512-point table over the interval [-1,1] will have its
  3477. origin at location 257 (at the start of the 2nd half).  Provided
  3478. the extended guard point is requested, both fn(-1) and fn(1) will
  3479. exist in the table.  
  3480.  
  3481. GEN03 is useful in conjunction with table or tablei for audio
  3482. waveshaping (sound modification by non-linear distortion). 
  3483. Coefficients to produce a particular formant from a sinusoidal
  3484. lookup index of known amplitude can be determined at
  3485. preprocessing time using algorithms such as Chebyshev formulae. 
  3486. See also GEN13.  
  3487.  
  3488.  
  3489. Example: 
  3490.  
  3491.  
  3492.      f   1  0   1025  3  -1  1  5  4  3  2  2  1 
  3493.  
  3494.  
  3495. This calls GEN03 to fill a table with a 4th order polynomial
  3496. function over the x-interval -1 to 1.  The origin will be at the
  3497. offset position 512.  The function is post-normalized.  
  3498.  
  3499. GEN04 
  3500.  
  3501. This subroutine generates a normalizing function by examining the
  3502. contents of an existing table.  
  3503.  
  3504.  
  3505.      f  #  time  size  4  source#  sourcemode 
  3506.  
  3507.  
  3508. size - number of points in the table.  Should be power-of-2 plus
  3509. 1.  Must not exceed (except by 1) the size of the source table
  3510. being examined; limited to just half that size if the sourcemode
  3511. is of type offset (see below).  
  3512.  
  3513. source #  -  table number of stored function to be examined.
  3514.  
  3515. sourcemode - a coded value, specifying how the source table is to
  3516. be scanned to obtain the normalizing function.  Zero indicates
  3517. that the source is to be scanned from left to right.  Non-zero
  3518. indicates that the source has a bipolar structure; scanning will
  3519. begin at the mid-point and progress outwards, looking at pairs of
  3520. points equidistant from the center.  
  3521.  
  3522.  
  3523. Note: 
  3524.  
  3525. The normalizing function derives from the progressive absolute
  3526. maxima of the source table being scanned.  The new table is
  3527. created left-to-right, with stored values equal to 1/(absolute
  3528. maximum so far scanned).  Stored values will thus begin with
  3529. 1/(first value scanned), then get progressively smaller as new
  3530. maxima are encountered.  For a source table which is normalized
  3531. (values <= 1), the derived values will range from 1/(first value
  3532. scanned) down to 1.  If the first value scanned is zero, that
  3533. inverse will be set to 1.  
  3534.  
  3535. The normalizing function from GEN04 is not itself normalized.  
  3536.  
  3537. GEN04 is useful for scaling a table-derived signal so that it has
  3538. a consistent peak amplitude.  A particular application occurs in
  3539. waveshaping when the carrier (or indexing) signal is less than
  3540. full amplitude.  
  3541.  
  3542.  
  3543. Example: 
  3544.  
  3545.  
  3546.      f   2   0   512   4    1   1 
  3547.  
  3548.  
  3549. This creates a normalizing function for use in connection with
  3550. the GEN03 table 1 example.  Midpoint bipolar offset is specified. 
  3551.  
  3552.  
  3553. GEN05, GEN07 
  3554.  
  3555. These subroutines are used to construct functions from segments
  3556. of exponential curves (GEN05) or straight lines (GEN07).  
  3557.  
  3558.  
  3559.      f  #    time    size   5   a   n1   b   n2   c  .  .  .  
  3560.      f  #    time    size   7   a   n1   b   n2   c  .  .  .  
  3561.  
  3562.  
  3563. size - number of points in the table.  Must be a power of 2 or
  3564. power-of-2 plus 1 (see f statement).  
  3565.  
  3566. a, b, c, etc.  - ordinate values, in odd-numbered pfields p5, p7,
  3567. p9, .  .  .  For GEN05 these must be nonzero and must be alike in
  3568. sign.  No such restrictions exist for GEN07.  
  3569.  
  3570. n1, n2, etc.  - length of segment (no.  of storage locations), in
  3571. even-numbered pfields.  Cannot be negative, but a zero is
  3572. meaningful for specifying discontinuous waveforms (e.g. in the
  3573. example below).  The sum n1 + n2 + ....  will normally equal size
  3574. for fully specified functions.  If the sum is smaller, the
  3575. function locations not included will be set to zero; if the sum
  3576. is greater, only the first size locations will be stored.  
  3577.  
  3578.  
  3579. Note: 
  3580.  
  3581. If p4 is positive, functions are post-normalized (rescaled to a
  3582. maximum absolute value of 1 after generation).  A negative p4
  3583. will cause rescaling to be skipped.  
  3584.  
  3585. Discrete-point linear interpolation implies an increase or
  3586. decrease along a segment by equal differences between adjacent
  3587. locations; exponential interpolation implies that the progression
  3588. is by equal ratio.  In both forms the interpolation from a to b
  3589. is such as to assume that the value b will be attained in the n +
  3590. 1th location.  For discontinuous functions, and for the segment
  3591. encompassing the end location, this value will not actually be
  3592. reached, although it may eventually appear as a result of final
  3593. scaling.  
  3594.  
  3595.  
  3596.  
  3597. Example: 
  3598.  
  3599.      f   1   0   256   7   0   128   1   0   -1   128   0 
  3600.  
  3601. This describes a single-cycle sawtooth whose discontinuity is
  3602. mid-way in the stored function.  
  3603.  
  3604. GEN06
  3605.  
  3606. This subroutine will generate a function comprised of segments of
  3607. cubic polynomials, spanning specified points just three at a
  3608. time.  
  3609.  
  3610.  
  3611.      f  #   time   size   6   a   n1   b   n2   c   n3   d .  . 
  3612. .  
  3613.  
  3614.  
  3615. size - number of points in the table.  Must be a power off or
  3616. power-of-2 plus 1 (see f statement).  
  3617.  
  3618. a, c, e, ...  - local maxima or minima of successive segments,
  3619. depending on the relation of these points to adjacent inflexions. 
  3620. May be either positive or negative.  
  3621.  
  3622. b, d, f, ...  - ordinate values of points of inflexion at the
  3623. ends of successive curved segments.  May be positive or negative. 
  3624.  
  3625.  
  3626. n1, n2, n3...  - number of stored values between specified
  3627. points.  Cannot be negative, but a zero is meaningful for
  3628. specifying discontinuities.  The sum n1 + n2 + ...  will normally
  3629. equal size for fully specified functions.  (for details, see
  3630. GEN05).  
  3631.  
  3632.  
  3633.  
  3634. Note: 
  3635.  
  3636. GEN06 constructs a stored function from segments of cubic
  3637. polynomial functions.  Segments link ordinate values in groups of
  3638. 3: point of inflexion, maximum/minimum, point of inflexion.  The
  3639. first complete segment encompasses b,c,d and has length n2 + n3,
  3640. the next encompasses d,e,f and has length n4 + n5, etc.  The
  3641. first segment (a,b with length n1) is partial with only one
  3642. inflexion; the last segment may be partial too.  Although the
  3643. inflexion points b,d,f ...  each figure in two segments (to the
  3644. left and right), the slope of the two segments remains
  3645. independent at that common point (i.e.  the 1st derivative will
  3646. likely be discontinuous).  When a,c,e...  are alternately maximum
  3647. and minimum, the inflexion joins will be relatively smooth; for
  3648. successive maxima or successive minima the inflexions will be
  3649. comb-like.  
  3650.  
  3651.  
  3652.  
  3653. Example: 
  3654.  
  3655.      f    1    0    65    6   0   16   .5    16   1   16   0   16 
  3656.  -1 
  3657.  
  3658. This creates a curve running 0 to 1 to -1, with a minimum,
  3659. maximum and minimum at these values respectively.  Inflexions are
  3660. at  .5 and 0, and are relatively smooth.  
  3661.  
  3662. GEN08
  3663.  
  3664. This subroutine will generate a piecewise cubic spline curve, the
  3665. smoothest possible through all specified points.  
  3666.  
  3667.  
  3668.      f   #    time    size    8    a    n1    b    n2    c    n3  
  3669.  d  .  .  .  
  3670.  
  3671.  
  3672. size - number of points in the table.  Must be a power of 2 or
  3673. power-of-2 plus 1 (see f statement).  
  3674.  
  3675. a, b, c ... - ordinate values of the function.  
  3676.  
  3677. n1, n2, n3  ... - length of each segment measured in stored
  3678. values.  May not be zero, but may be fractional.  A particular
  3679. segment may or may not actually store any values; stored values
  3680. will be generated at integral points from the beginning of the
  3681. function.  The sum n1 + n2 + ... will normally equal size for
  3682. fully specified functions.  
  3683.  
  3684.  
  3685. Note: 
  3686.  
  3687. GEN08 constructs a stored table from segments of cubic polynomial
  3688. functions.  Each segment runs between two specified points but
  3689. depends as well on their neighbors on each side.  Neighboring
  3690. segments will agree in both value and slope at their common
  3691. point.  (The common slope is that of a parabola through that
  3692. point and its two neighbors).  The slope at the two ends of the
  3693. function is constrained to be zero (flat).  
  3694.  
  3695. Hint:  to make a discontinuity in slope or value in the function
  3696. as stored, arrange a series of points in the interval between two
  3697. stored values; likewise for a non-zero boundary slope.  
  3698.  
  3699.  
  3700.  
  3701. Examples: 
  3702.  
  3703.      f    1    0    65    8    0    16    0    16    1    16    0 
  3704.   16    0 
  3705.  
  3706. This example creates a curve with a smooth hump in the middle,
  3707. going briefly negative outside the hump then flat at its ends.  
  3708.  
  3709.  
  3710.      f    2    0    65    8    0    16    0   .1    0    15.9   
  3711. 1    15.9    0    .1    0    16    0 
  3712.  
  3713. This example is similar, but does not go negative.  
  3714.  
  3715. GEN09, GEN10, GEN19 
  3716.  
  3717. These subroutines generate composite waveforms made up of
  3718. weighted sums of simple sinusoids.  The specification of each
  3719. contributing partial requires 3 pfields using GEN09, 1 using
  3720. GEN10, and 4 using GEN19. 
  3721.  
  3722.  
  3723.      f   #    time    size    9      pna     stra    phsa    pnb  
  3724.  strb    phsb  .  .  .  
  3725.      f   #    time    size  10      str1     str2    str3    
  3726. str4  .  .  .  .  
  3727.      f   #    time    size  19      pna     stra    phsa    dcoa  
  3728. pnb    strb    phsb   dcob  .  .  .  
  3729.  
  3730.  
  3731. size - number of points in the table.  Must be a power of 2 or
  3732. power-of-2 plus 1 (see f statement).  
  3733.  
  3734. pna, pnb, etc.  - partial no.  (relative to a fundamental that
  3735. would occupy size locations per cycle) of sinusoid a, sinusoid b,
  3736. etc.  Must be positive, but need not be a whole number, i.e.,
  3737. non-harmonic partials are permitted.  Partials may be in any
  3738. order.  
  3739.  
  3740. stra, strb, etc.  - strength of partials pna, pnb, etc.  These
  3741. are relative strengths, since the composite waveform may be
  3742. rescaled later.  Negative values are permitted and imply a 180
  3743. degree phase shift.  
  3744.  
  3745. phsa, phsb, etc.  - initial phase of partials pna, pnb, etc.,
  3746. expressed in degrees.  
  3747.  
  3748. dcoa, dcob,  etc.  - DC offset of partials pna, pnb, etc.  This
  3749. is applied after strength scaling, i.e. a value of 2 will lift a
  3750. 2-strength sinusoid from range [-2,2] to range [0,4]  (before
  3751. later rescaling).
  3752.  
  3753. str1, str2, str3, etc.  - relative strengths of the fixed
  3754. harmonic partial numbers 1,2,3, etc., beginning in p5.  Partials
  3755. not required should be given a strength of zero.  
  3756.  
  3757. Note: 
  3758.  
  3759. These subroutines generate stored functions as sums of sinusoids
  3760. of different frequencies.  The two major restrictions on
  3761. GEN10עthat the partials be harmonic and in phaseעdo not apply to
  3762. GEN09 or GEN19.  
  3763.  
  3764. In each case the composite wave, once drawn, is then rescaled to
  3765. unity if p4 was positive.  A negative p4 will cause rescaling to
  3766. be skipped.  
  3767.  
  3768.  
  3769.  
  3770. Examples: 
  3771.  
  3772.      f    1    0    1024      9    1    3      0    3    1    0   
  3773. 9   .3333    180 
  3774.      f    2    0    1024    19    .5   1  270    1
  3775.  
  3776. f 1 combines partials l, 3 and 9 in the relative strengths in
  3777. which they are found in a square wave, except that partial 9 is
  3778. upside down.   f 2 creates a rising sigmoid [0 - 2].   Both will
  3779. be rescaled.
  3780.  
  3781. GEN11 
  3782.  
  3783. This subroutine generates an additive set of cosine partials, in
  3784. the manner of Csound generators buzz and gbuzz.  
  3785.  
  3786.  
  3787.      f    #    time    size    11    nh    lh    r 
  3788.  
  3789.  
  3790. size - number of points in the table.  Must be a power of 2 or
  3791. power-of-2 plus 1 (see f statement).  
  3792.  
  3793. nh - number of harmonics requested.  Must be positive.  
  3794.  
  3795. lh (optional) - lowest harmonic partial present.  Can be
  3796. positive, zero or negative.  The set of partials can begin at any
  3797. partial number and proceeds upwards; if lh is negative, all
  3798. partials below zero will reflect in zero to produce positive
  3799. partials without phase change (since cosine is an even function),
  3800. and will add constructively to any positive partials in the set. 
  3801. The default value is 1.  
  3802.  
  3803. r (optional) - multiplier in an amplitude coefficient series. 
  3804. This is a power series: if the lhth partial has a strength
  3805. coefficient of A the (lh + n)th partial will have a coefficient
  3806. of A * r**n, i.e.  strength values trace an exponential curve.  r
  3807. may be positive, zero or negative, and is not restricted to
  3808. integers.  The default value is 1.  
  3809.  
  3810.  
  3811. Note: 
  3812.  
  3813. This subroutine is a non-time-varying version of the csound buzz
  3814. and gbuzz generators, and is similarly useful as a complex sound
  3815. source in subtractive synthesis.  With lh and r present it
  3816. parallels gbuzz; with both absent or equal to 1 it reduces to the
  3817. simpler buzz (i.e. nh equal-strength harmonic partials beginning
  3818. with the fundamental).  
  3819.  
  3820. Sampling the stored waveform with an oscillator is more efficient
  3821. than using dynamic buzz units.  However, the spectral content is
  3822. invariant, and care is necessary lest the higher partials exceed
  3823. the Nyquist during sampling to produce foldover.  
  3824.  
  3825.  
  3826.  
  3827. Examples: 
  3828.  
  3829.      f  1    0    2049   11    4 
  3830.      f  2    0    2049   11    4    1    1 
  3831.      f  3    0    2049  -11    7    3   .5 
  3832.  
  3833. The first two tables will contain identical band-limited pulse
  3834. waves of four equal-strength harmonic partials beginning with the
  3835. fundamental.  The third table will sum seven consecutive
  3836. harmonics, beginning with the third, and at progressively weaker
  3837. strengths (1, .5, .25, .125 .  .  .).  It will not be
  3838. post-normalized.  
  3839.  
  3840. GEN12 
  3841.  
  3842. This generates the log of a modified Bessel function of the
  3843. second kind, order 0, suitable for use in amplitude-modulated FM. 
  3844.  
  3845.  
  3846.  
  3847.      f    #    time    size    -12    xint 
  3848.  
  3849.  
  3850. size - number of points in the table.  Must be a power of 2 or a
  3851. power-of-2 plus 1 (see f statement).  The normal value is
  3852. power-of-2 plus 1.  
  3853.  
  3854. xint - specifies the x interval [0 to +int] over which the
  3855. function is defined.  
  3856.  
  3857.  
  3858. Note: 
  3859.  
  3860. This subroutine draws the natural log of a modified Bessel
  3861. function of the second kind, order 0 (commonly written as I
  3862. subscript 0), over the x-interval requested.  The call should
  3863. have rescaling inhibited.  
  3864.  
  3865. The function is useful as an amplitude scaling factor in
  3866. cycle-synchronous amplitude-modulated FM.  (See Palamin &
  3867. Palamin, J. Audio Eng. Soc., 36/9, Sept. 1988, pp.671-684.) The
  3868. algorithm is interesting because it permits the normally
  3869. symmetric FM spectrum to be made asymmetric around a frequency
  3870. other than the carrier, and is thereby useful for formant
  3871. positioning.  By using a table lookup index of I(r - 1/r), where
  3872. I is the FM modulation index and r is an exponential parameter
  3873. affecting partial strengths, the Palamin algorithm becomes
  3874. relatively efficient, requiring only oscil's, table lookups, and
  3875. a single exp call.  
  3876.  
  3877.  
  3878. Example: 
  3879.  
  3880.      f    1    0    2049    -12    20 
  3881.  
  3882. This draws an unscaled ln(I0(x)) from 0 to 20.  
  3883.  
  3884. GEN13, GEN14 
  3885.  
  3886. These subroutines use Chebyshev coefficients to generate stored
  3887. polynomial functions which, under waveshaping, can be used to
  3888. split a sinusoid into harmonic partials having a predefinable
  3889. spectrum.  
  3890.  
  3891.  
  3892.      f    #    time    size    13    xint    xamp    h0    h1   h2  .  .  .  hn 
  3893.      f    #    time    size    14    xint    xamp    h0    h1   h2  .  .  .  hn 
  3894.  
  3895.  
  3896. size - number of points in the table.  Must be a power of 2 or a
  3897. power-of-2 plus 1 (see f statement).  The normal value is
  3898. power-of-2 plus 1.  
  3899.  
  3900. xint - provides the left and right values [-xint,  +xint] of the
  3901. x interval over which the polynomial is to be drawn.  These
  3902. subroutines both call GEN03 to draw their functions; the p5 value
  3903. here is therefor expanded to a negative-positive p5,p6 pair
  3904. before GEN03 is actually called.  The normal value is 1.  
  3905.  
  3906. xamp - amplitude scaling factor of the sinusoid input that is
  3907. expected to produce the following spectrum.  
  3908.  
  3909. h0, h1, h2, ....  hn - relative strength of partials 0 (DC), 1
  3910. (fundamental), 2 ...  that will result when a sinusoid of
  3911. amplitude xamp * int(size/2)/xint is waveshaped using this
  3912. function table.  These values thus describe a frequency spectrum
  3913. associated with a particular factor xamp of the input signal.  
  3914.  
  3915.  
  3916. Note: 
  3917.  
  3918. GEN13 is the function generator normally employed in standard
  3919. waveshaping.  It stores a polynomial whose coefficients derive
  3920. from the Chebyshev polynomials of the first kind, so that a
  3921. driving sinusoid of strength xamp will exhibit the specified
  3922. spectrum at output.  Note that the evolution of this spectrum is
  3923. generally not linear with varying xamp.  However, it is
  3924. bandlimited (the only partials to appear will be those specified
  3925. at generation time); and the partials will tend to occur and to
  3926. develop in ascending order (the lower partials dominating at low
  3927. xamp, and the spectral richness increasing for higher values of
  3928. xamp).  A negative hn value implies a 180 degree phase shift of
  3929. that partial; the requested full-amplitude spectrum will not be
  3930. affected by this shift, although the evolution of several of its
  3931. component partials may be.  The pattern +,+,-,-,+,+,...  for
  3932. h0,h1,h2...  will minimize the normalization problem for low xamp
  3933. values (see above), but does not necessarily provide the
  3934. smoothest pattern of evolution.  
  3935.  
  3936. GEN14 stores a polynomial whose coefficients derive from
  3937. Chebyshevs of the second kind.  
  3938.  
  3939.  
  3940. Example: 
  3941.  
  3942.      f    1    0   1025    13    1   1    0    5    0    3    0   1 
  3943.  
  3944. This creates a function which, under waveshaping, will split a
  3945. sinusoid into 3 odd-harmonic partials of relative strength 5:3:1. 
  3946.  
  3947.  
  3948. GEN15
  3949.  
  3950. This subroutine creates two tables of stored polynomial
  3951. functions, suitable for use in phase quadrature operations.  
  3952.  
  3953.  
  3954.      f    #    time    size    15    xint    xamp    h0    phs0   h1    phs1    h2    phs2  .  .  .  
  3955.  
  3956.  
  3957. size - number of points in the table.  Must be a power of 2 or a
  3958. power-of-2 plus 1 (see f statement).  The normal value is
  3959. power-of-2 plus 1.  
  3960.  
  3961. xint - provides the left and right values [-xint,  +xint] of the
  3962. x interval over which the polynomial is to be drawn.  This
  3963. subroutine will eventually call GEN03 to draw both functions;
  3964. this p5 value is therefor expanded to a negative-positive p5, p6
  3965. pair before GEN03 is actually called.  The normal value is 1.
  3966.  
  3967.  
  3968. xamp - amplitude scaling factor of the sinusoid input that is
  3969. expected to produce the following spectrum.  
  3970.  
  3971. h0, h1, h2, ... hn - relative strength of partials 0 (DC), 1
  3972. (fundamental), 2 ...  that will result when a sinusoid of
  3973. amplitude xamp * int(size/2)/xint is waveshaped using this
  3974. function table.  These values thus describe a frequency spectrum
  3975. associated with a particular factor xamp of the input signal.  
  3976.  
  3977. phs0, phs1, ...  - phase in degrees of desired harmonics h0, h1,
  3978. ...  when the two functions of GEN15 are used with phase
  3979. quadrature.  
  3980.  
  3981.  
  3982. Note: 
  3983.  
  3984. GEN15 creates two tables of equal size, labelled f # and f # + 1. 
  3985. Table # will contain a Chebyshev function of the first kind,
  3986. drawn using GEN03 with partial strengths h0cos(phs0),
  3987. h1cos(phs1), ...  Table #+1 will contain a Chebyshev function of
  3988. the 2nd kind by calling GEN14 with partials h1sin(phs1),
  3989. h2sin(phs2),...  (note the harmonic displacement).  The two
  3990. tables can be used in conjunction in a waveshaping network that
  3991. exploits phase quadrature.  
  3992.  
  3993.  
  3994.  
  3995. GEN17
  3996.  
  3997. This subroutine creates a step function from given x-y pairs.
  3998.  
  3999.  
  4000.      f    #    time    size    17    x1  a  x2  b  x3  c  .  .  . 
  4001.  
  4002.  
  4003.  
  4004. size - number of points in the table.  Must be a power of 2 or a
  4005. power-of-2 plus 1 (see f statement).  The normal value is
  4006. power-of-2 plus 1.
  4007.  
  4008. x1, x2, x3, etc. - x-ordinate values, in ascending order, 0
  4009. first.
  4010.  
  4011. a, b, c, etc. - y-values at those x-ordinates, held until the
  4012. next x-ordinate.
  4013.  
  4014.  
  4015. This subroutine creates a step function of x-y pairs whose
  4016. y-values are held to the right.  The right-most y-value is then
  4017. held to the end of the table.  The function is useful for mapping
  4018. one set of data values onto another, such as MIDI note numbers
  4019. onto sampled sound ftable numbers  (see loscil).
  4020.  
  4021.  
  4022. Example:
  4023.  
  4024.      f  1  0  128  -17   0  1   12  2   24  3   36  4   48  5  60  6   72  7   84  8
  4025.  
  4026. This describes a step function with 8 successively increasing
  4027. levels, each 12 locations wide except the last which extends its
  4028. value to the end of the table.  Rescaling is inhibited.  Indexing
  4029. into this table with a MIDI note-number would retrieve a
  4030. different value every octave up to the eighth, above which the
  4031. value returned would remain the same.
  4032.  
  4033. 5.  SCOT:  A Score Translator
  4034.  
  4035.  
  4036. Scot is a language for describing scores in a fashion that
  4037. parallels traditional music notation.  Scot is also the name of a
  4038. program which translates scores written in this language into
  4039. standard numeric score format so that the score can be performed
  4040. by Csound.  The result of this translation is placed in a file
  4041. called score.  A score file written in Scot (named file.sc, say)
  4042. can be sent through the translator by the command
  4043.  
  4044.      scot  file.sc
  4045.  
  4046. The resulting numeric score can then be examined for errors,
  4047. edited, or performed by typing
  4048.  
  4049.      csound  file.orc  score
  4050.  
  4051. Alternatively, the command
  4052.  
  4053.      csound  file.orc  -S file.sc
  4054.  
  4055. would combine both processes by informing Csound of the initial
  4056. score format.
  4057.  
  4058. Internally, a Scot score has at least three parts:  a section to
  4059. define instrument names, a section to define functions, and one
  4060. or more actual score sections.  It is generally advisable to keep
  4061. score sections short to facilitate finding errors.  The overall
  4062. layout of a Scot score has three main sections:
  4063.  
  4064.      orchestra { .... }
  4065.      functions { .... }
  4066.      score { .... }
  4067.  
  4068. The last two sections may be repeated as many times as desired. 
  4069. The functions section is also optional.  Throughout this Scot
  4070. document, bear in mind that you are free to break up each of
  4071. these divisions into as many lines as seem convenient, or to
  4072. place a carriage return anywhere you are allowed to insert a
  4073. space, including before and after the curly brackets. 
  4074. Furthermore, you may use as many spaces or tabs as you need to
  4075. make the score easy to read.  Scot imposes no formatting
  4076. restrictions except that numbers, instrument names, and keywords
  4077. (for example, orchestra) may not be broken with spaces.  You may
  4078. insert comments (such as measure numbers) anywhere in the score
  4079. by preceding them with a semicolon.  A semicolon causes Scot to
  4080. ignore the rest of a line.
  4081.  
  4082. Orchestra Declaration Section
  4083.  
  4084. The orchestra section of a Scot score serves to designate
  4085. instrument names for use within the score.  This is a matter of
  4086. convenience, since an orchestra knows instruments only by
  4087. numbers, not names.  If you declare three instruments, such as:
  4088.  
  4089.      orchestra { flute=1 cello=2 trumpet=3 }
  4090.  
  4091. Csound will neither know nor care what you have named the note
  4092. lists.  However, when you use the name $flute, Scot will know you
  4093. are referring to instr 1 in the orchestra, $cello will refer to
  4094. instr 2, and $trumpet will be instr 3.  You may meaningfully skip
  4095. numbers or give several instruments the same number.  It is up to
  4096. you to make sure that your orchestra has the correct instruments
  4097. and that the association between these names and the instruments
  4098. is what you intend.  There is no limit (or a very high one, at
  4099. least) as to how many instruments you can declare.
  4100.  
  4101. Function Declaration Section
  4102.  
  4103. The major purpose of this division is to allow you to declare
  4104. function tables for waveforms, envelopes, etc.  These functions
  4105. are declared exactly as specified for Csound.  In fact,
  4106. everything you type between the brackets in this section will be
  4107. passed directly to the resulting numeric score with no
  4108. modification, so that mistakes will not be caught by the Scot
  4109. program, but rather by the subsequent performance.  You can use
  4110. this section to write notes for instruments for which traditional
  4111. pitch-rhythm notation is inappropriate.  The most common example
  4112. would be turning on a reverb instrument.  Instruments referenced
  4113. in this way need not appear in the Scot orchestra declaration. 
  4114. Here is a possible function declaration:
  4115.  
  4116.      functions {
  4117.      f1 0 256 10 1 0 .5 0 .3
  4118.      f2 0 256 7 0 64 1 64 .7 64 0
  4119.      i9 0 -1 3           ; this turns on instr 9
  4120.      }
  4121.  
  4122. Score Section
  4123.  
  4124. The Scot statements contained inside the braces of each score
  4125. statement is translated into a numeric score Section (q.v.).  It
  4126. is wise to keep score sections small, say seven or eight measures
  4127. of five voices at a time.  This avoids overloading the system,
  4128. and simplifies error checking.
  4129.  
  4130. The beginning of the score section is specified by typing:
  4131.  
  4132.      score {
  4133.  
  4134. Everything which follows until the braces are closed is within a
  4135. single section.  Within this section you write measures of notes
  4136. in traditional pitch and rhythm notation for any of the
  4137. instrument names listed in your orchestra declaration. These
  4138. notes may carry additional information such as slurs, ties and
  4139. parameter fields.  Let us now consider the format for notes
  4140. entered in a Scot score.
  4141.  
  4142. The first thing to do is name the instrument you want and the
  4143. desired meter.  For example, to write some 4/4 measures for the
  4144. cello, type:
  4145.  
  4146.      $cello
  4147.      !ti "4/4"
  4148.  
  4149. The dollar sign and exclamation point tell Scot that a special
  4150. declarator follows. The time signature declarator is optional; 
  4151. if present, Scot will check the number of beats in each measure
  4152. for you.
  4153.  
  4154. Pitch and Rhythm
  4155.  
  4156. The two basic components of a note statement are the pitch and
  4157. duration.  Pitch is specified using the alphabetic note name, and
  4158. duration is specified using numeric characters.  Duration is
  4159. indicated at the beginning of the note as a number representing
  4160. the division of a whole beat.  You may always find the number
  4161. specifying a given duration by thinking of how many times that
  4162. duration would fit in a 4/4 measure.  Also, if the duration is
  4163. followed by a dot (`.') it is increased by 50%, exactly as in
  4164. traditional notation.  Some sample durations are listed below:
  4165.  
  4166.      whole note               1
  4167.      half note                2
  4168.      double dotted quarter    4..
  4169.      dotted quarter note      4.
  4170.      quarter note             4
  4171.      half note triplet        6
  4172.      eighth note              8
  4173.      eighth note triplet      12
  4174.      sixteenth note           16
  4175.      thirty-second note       32
  4176.  
  4177. Pitch is indicated next by first (optionally) specifying the
  4178. register and then the note name, followed by an accidental if
  4179. desired.  Normally, the "octave following" feature is in effect. 
  4180. This feature causes any note named to lie within the interval of
  4181. an augmented fourth of the previous note, unless a new register
  4182. is chosen.  The first note you write will always be within a
  4183. fourth of middle c unless you choose a different register.
  4184.  
  4185. For example, if the first note of an instrument part is notated g
  4186. flat, the scot program assigns the pitch corresponding to the g
  4187. flat below middle c.  On the other hand, if the first note is f
  4188. sharp, the pitch assigned will be the f sharp above middle c. 
  4189. Changes of register are indicated by a preceding apostrophe for
  4190. each octave displacement upward or a preceding comma for each
  4191. octave displacement downward.  Commas and apostrophes always
  4192. displace the pitch by the desired number of octaves starting from
  4193. that note which is within an augmented fourth of the previous
  4194. pitch.
  4195.  
  4196. If you ever get lost, prefacing the pitch specification with an
  4197. `=' returns the reference to middle c.  It is usually wise to use
  4198. the equals sign in your first note statement and whenever you
  4199. feel uncertain as to what the current registration is.  Let us
  4200. now write two measures for the cello part, the first starting in
  4201. the octave below middle c and the second repeating but starting
  4202. in the octave above middle c:
  4203.  
  4204.      $cello
  4205.      !ti "4/4"
  4206.      4=g 4e 4d 4c/ 4='g 4e 4d 4c
  4207.  
  4208. As you can see, a slash indicates a new measure and we have
  4209. chosen to use the dummy middle c to indicate the new register.  A
  4210. more convenient way of notating these two measures would be to
  4211. type the following:
  4212.  
  4213.      $cello
  4214.      !ti "4/4"
  4215.      4=g e d c/ ''g e d c
  4216.  
  4217. You may observe in this example that the quarter note duration
  4218. carries to the following notes when the following durations are
  4219. left unspecified.  Also, two apostrophes indicate an upward pitch
  4220. displacement of two octaves from two g's below middle c, where
  4221. the pitch would have fallen without any modification.  It is
  4222. important to remember three things, then, when specifying
  4223. pitches:
  4224.  
  4225. 1)  Note pitches specified by letter name only (with or without
  4226. accidental) will always fall within an interval of a fourth from
  4227. the preceding pitch.
  4228.  
  4229. 2)  These pitches can be octave displaced upward or downward by
  4230. preceding the note letter with the desired number of apostrophes
  4231. or commas.
  4232.  
  4233. 3)  If you are unsure of the current register, you may begin the
  4234. pitch component of the note with an equals sign which acts as a
  4235. dummy middle c.
  4236.  
  4237. The pitch may be modified by an accidental after the note name:
  4238.  
  4239.      n                   natural
  4240.      #                   sharp
  4241.      -  (hyphen)         flat
  4242.      ##                  double sharp
  4243.      -- (double hyphen)  double flat
  4244.  
  4245. Accidentals are carried throughout the measure just as in
  4246. traditional music notation.  However, an accidental specified
  4247. within a measure will hold for that note in all registers, in
  4248. contrast with traditional notation.  Therefore, make sure to
  4249. specify n when you no longer want an accidental applied to that
  4250. pitch-class.
  4251.  
  4252. Pitches entered in the Scot score are translated into the
  4253. appropriate octave point pitch-class value and appear as
  4254. parameter p5 in the numeric score output.  This means you must
  4255. design your instruments to accept p5 as pitch.
  4256.  
  4257. Rests are notated just like notes but using the letter r instead
  4258. of a pitch name.  4r therefore indicates a quarter rest and 1r a
  4259. whole rest.  Durations carry from rest to rest or to following
  4260. pitches as mentioned above.
  4261.  
  4262. The tempo in beats per minute is specified in each section by
  4263. choosing a single instrument part and using tempo statements
  4264. (e.g. t90) at the various points in the score as needed.  A
  4265. quarter note is interpreted as a single beat, and tempi are
  4266. interpolated between the intervening beats (see score t statement).
  4267.  
  4268.  
  4269. Scot Example I
  4270.  
  4271.  
  4272.  
  4273. A Scot encoding of this score might appear as follows:
  4274.  
  4275.      ; A BASIC Tune
  4276.      orchestra { guitar=1 bass=2 }
  4277.      functions  {
  4278.      f1 0 512 10 1 .5 .25 .126
  4279.      f2 0 256  7 1 120 1 8 0 128 1
  4280.      }
  4281.      score     {  ;section 1
  4282.      $guitar
  4283.      !ti "4/4"
  4284.      4=c 8d e- f r 4='c/
  4285.      8.b- 16a a- g  g- f  4e- c/
  4286.      $bass
  4287.      2=,,c 'a-/
  4288.      g  =,c/
  4289.      }
  4290.      score     {  ;section 2
  4291.      $guitar
  4292.      !ti "4/4"
  4293.      6='c r c 4..c## 16e- /
  4294.      6f r f 4..f## 16b /
  4295.      $bass
  4296.      4=,,c 'g, c 'g/
  4297.      2=a-  g /
  4298.      }
  4299.  
  4300. The score resulting from this Scot notation is shown at the end
  4301. of this chapter.
  4302.  
  4303. Groupettes
  4304.  
  4305. Duration numbers can have any integral value; for instance,
  4306.  
  4307.      !time "4/4"
  4308.      5cdefg/
  4309.  
  4310. would encode a measure of 5 in the time of 4 quarter notes. 
  4311. However, specification of arbitrary rhythmic groupings in this
  4312. way is at best awkward.  Instead, arbitrary portions of the score
  4313. section may be enclosed in groupette brackets.  The durations of
  4314. all notes inside groupette brackets will be multiplied by a
  4315. fraction n/d, where the musical meaning is d in the time of n. 
  4316. Assuming d and n here are integers, groupette brackets may take
  4317. these several forms:
  4318.  
  4319.      {d:n:     ....      :}   d in the time of n
  4320.      {d:: ....      :}   n will be the largest power of 2 less than d
  4321.      {:   ....      :}   d=3, n=2 (normal triplets)
  4322.  
  4323. It can be seen that the second and third form are abbreviations
  4324. for the more common kinds of groupettes.  (Observe the
  4325. punctuation of each form carefully.)  Groupettes may be nested to
  4326. a reasonable depth.  Also, groupette factors apply only after the
  4327. written duration is carried from note to note.  Thus, the
  4328. following example is a correct specification for two measures of
  4329. 6/8 time:
  4330.  
  4331.      !time "6/8" 8cde {4:3: fgab :} / crc 4.c /
  4332.  
  4333. The notes inside the groupette are 4 in the space of 3 8th notes,
  4334. and the written-8th-note duration carries normally into the next
  4335. measure.  This closely parallels the way groupette brackets and
  4336. note durations interact in standard notation.
  4337.  
  4338. Slurs and Ties
  4339.  
  4340. Now that you understand part writing in the Scot language, we can
  4341. start discussing more elaborate features.  Immediately following
  4342. the pitch specification of each note, one may indicate a slur or
  4343. a tie into the next note (assuming there is one), but not both
  4344. simultaneously.  The slur is typed as a single underscore (`_')
  4345. and a tie as a double underscore (`__').  Despite the surface
  4346. similarity, there is a substantial difference in the effect of
  4347. these modifiers.
  4348.  
  4349. For purposes of Scot, tied notes are notes which, although
  4350. comprised of several graphic symbols, represent only a single
  4351. musical event.  (Tied notes are necessary in standard music
  4352. notation for several reasons, the most common being notes which
  4353. span a measure line and notes with durations not specifiable with
  4354. a single symbol, such as quarter note tied to a sixteenth.) 
  4355. Notes which are tied together are summed by duration and output
  4356. by Scot as a single event.  This means you cannot, for example,
  4357. change the parameters of a note in the middle of a tie (see
  4358. below).  Two or more notes may be tied together, as in the
  4359. following example, which plays an f# for eleven beats:
  4360.  
  4361.      !ti "4/4"
  4362.      1 f#__ / 1 f#__ / 2. f# 4r /
  4363.  
  4364. By contrast, slurred notes are treated as distinct notes at the
  4365. Csound level, and may be of arbitrary pitch.  The presence of a
  4366. slur is reflected in parameter p4, but the slur has no other
  4367. meaning beyond the interpretation of p4 by your instrument. 
  4368. Since instrument design is beyond the scope of this manual, it
  4369. will suffice for now to explain that the Scot program gives sets
  4370. p4 to one of four values depending on the existence of a slur
  4371. before and after the note in question.  This means Scot pays
  4372. attention not only to the slur attached to a given note, but
  4373. whether the preceding note specified a slur.  The four
  4374. possibilities are as follows, where the p4 values are taken to
  4375. apply to the note `d':
  4376.  
  4377.      4c  d         (no slur)       p4 = 0
  4378.      4c  d_        (slur after only)    p4 = 1
  4379.      4c_ d         (slur before only)   p4 = 2
  4380.      4c_ d_      (before & after)       p4 = 3
  4381.  
  4382. Parameters
  4383.  
  4384. The information contained in the Scot score notation we have
  4385. considered so far is manifested in the output score in parameters
  4386. p1 through p5 in the following way:
  4387.  
  4388.      p1:  instrument number
  4389.      p2:  initialization time of instrument
  4390.      p3:  duration
  4391.      p4:  slur information
  4392.      p5:  pitch information in octave point pitch-class notation
  4393.  
  4394. Any additional parameters you may want to enter are listed in
  4395. brackets as the last part of a note specification.  These
  4396. parameters start with p6 and are separated from each other with
  4397. spaces.  Any parameters not specified for a particular note have
  4398. their value carried from the most recently specified value. You
  4399. may choose to change some parameters and not others, in which
  4400. case you can type a dot (`.') for parameters whose values don't
  4401. change, and new values for those that do.  Alternatively, the
  4402. construction N:, where N is an integer, may be used to indicate
  4403. that the following parameter specifications apply to successive
  4404. parameters starting with parameter N.  For example:
  4405.  
  4406.      4e[15000 3 4 12:100 150] g_ d_[10000 . 5]    c
  4407.  
  4408. Here, for the first two quarter notes p6, p7, p8, p12, and p13
  4409. respectively assume the values 15000, 3, 4, 100, and 150.  The
  4410. values of p9 through p11 are either unchanged, or implicitly zero
  4411. if they have never been specified in the current section.  On the
  4412. third quarter note, the value of p6 is changed to 10000, and the
  4413. value of p8 is changed to 5.  All others are unchanged.
  4414.  
  4415. Normally, parameter values are treated as globalsעthat is, a
  4416. value specification will carry to successive notes if no new
  4417. value is specified.  However, if a parameter specification begins
  4418. with an apostrophe, the value applies locally to the current note
  4419. only, and will not carry to successive notes either horizontally
  4420. or vertically (see divisi below).
  4421.  
  4422. Pfield Macros
  4423.  
  4424. Scot has a macro text substitution facility which operates only
  4425. on the pfield specification text within brackets.  It allows
  4426. control values to be specified symbolically rather than
  4427. numerically.  Macro definitions appear inside brackets in the
  4428. orchestra section.  A single bracketed list of macro definitions
  4429. preceding the first instrument declaration defines macros which
  4430. apply to all instruments.  An additional bracketed list of
  4431. definitions may follow each instrument to specify macros that
  4432. apply to that particular instrument.
  4433.  
  4434.      orchestra {
  4435.           [ pp=2000 p=4000 mp=7000 mf=10000 f=20000 ff=30000
  4436.             modi = 11: w = 1 x = 2 y = 3 z = 4
  4437.             vib = "10:1 " novib = "10:0 1"
  4438.           ]
  4439.      violin = 1     [ pizz = " 20:1" arco = " 20:0" ]
  4440.      serpent = 3    [ ff = 25000 sfz = 'f sffz = 'ff]
  4441.      }
  4442.      score {
  4443.       $violin = 4c[mf modi z.y novib] d e a['f vib3] /
  4444.                8 b[pizz]c 4d[f] 2c[ff arco] /
  4445.       $serpent =, 4.c[mp modi y.x] 8b 2c /
  4446.                'g[f ], c[ff] /
  4447.      }
  4448.  
  4449. As can be seen from this example, a macro definition consists of
  4450. the macro name, which is a string of alphabetic characters,
  4451. followed by an equal sign, followed by the macro value.  As
  4452. usual, spaces, tabs, and newlines may be used freely.  The macro
  4453. value may contain arbitrary characters, and may be quoted if
  4454. spacing characters need to be included.
  4455.  
  4456. When a macro name is encountered in bracketed pfield lists in a
  4457. score section, that name is replaced with the macro text with no
  4458. additional punctuation supplied.  The macro text may itself
  4459. invoke other macros, although it is a serious error for a macro
  4460. to contain itself, directly or indirectly.  Since macro names are
  4461. identified as strings of alphabetic characters, and no additional
  4462. spaces are provided when a macro is expanded, macros may easily
  4463. perform such concatenations as found in the first serpent note
  4464. above, where the integer and fractional parts of a single pfield
  4465. are constructed.  Also, a macro may do no more than define a
  4466. symbolic pfield, as in the definition of modi.  The primary
  4467. intention of macros is in fact not only to reduce the number of
  4468. characters required, but also to enable symbolic definitions of
  4469. parameter numbers and parameter values.  For instance, a
  4470. particular instrument's interpretation of the dynamic ff can be
  4471. changed merely by changing a macro value, rather than changing
  4472. all occurrences of that particular value in the score.
  4473.  
  4474. Divisi
  4475.  
  4476. Notes may be stacked on top of each other by using a back arrow
  4477. (`<') between the notes of the divisi.  Each time Scot encounters
  4478. a back arrow, it understands that the following note is to start
  4479. at the same time as the note to the left of the back arrow.
  4480. Durations, accidentals and parameters carry from left to right
  4481. through the divisi.  Each time these are given new values, the
  4482. notes to the right of the back arrows also take on the new values
  4483. unless they are specified again.
  4484.  
  4485. When writing divisi you can stack compound events by enclosing
  4486. them in parentheses.  Also, divisi which occur at the end of the
  4487. measure must have the proper durations or the scot program will
  4488. mis-interpret the measure duration length.
  4489.  
  4490. Scot Example II
  4491.  
  4492. Scot encoding:
  4493.  
  4494.      orchestra { right=1 left=2 }
  4495.      functions { f1 0 256 10 1}
  4496.      score {
  4497.      $right !key "-b"
  4498.      ; since p5 is pitch, p7 is set to the pitch of next note
  4499.      !ti "2/4"
  4500.      !next p5 "p7"  ;since p5 is pitch, p7 refers to pitch of next note
  4501.      !next p6 "p8"  ;If p6 is vol, say, then p8 refers to vol of next note
  4502.      t90
  4503.      8r c[3 np5]<e<='g r c<f<a / t90 r d-<g<b r =c[5]<f<a__ /
  4504.      !ti "4/4"
  4505.      t80
  4506.      4d_<f__<(8a g__) 4c<(8fe)<4g 4.c<f<f 8r/
  4507.  
  4508.      $left  !key "-b"
  4509.      !next p5 "p7"
  4510.      !next p6 "p8"
  4511.      !ti "2/4"
  4512.      8=,c[3 np5] r f r/ e r f r/
  4513.      !ti "4/4"
  4514.      2b_[5]<(4=,b_c) 4.a<f 8r/
  4515.      }
  4516.  
  4517. Notice in this example that tempo statements occurred in
  4518. instrument `right' only.  Also, all notes had p6=3 until the
  4519. third measure, at which point p6 took on the value 5 for all
  4520. notes. The next parameter option used is described in Additional
  4521. Features.  The output score is given at the end.
  4522.  
  4523. Additional Features
  4524.  
  4525. Several options can be included in any of the individual
  4526. instrument parts within a section.  A sample statement follows
  4527. the description of each option.  The keyword which follows the
  4528. `!' in these statements may be abbreviated to the first two
  4529. characters.
  4530.  
  4531. Key Signatures
  4532.  
  4533. Any desired key signature is specified by listing the accidentals
  4534. as they occur in a key signature statement.  Thereafter, all
  4535. notes of that instrument part are sharpened or flattened
  4536. accordingly.  For example, for the key of D, type
  4537.  
  4538.      !key "#fc"
  4539.  
  4540. Accidental Following
  4541.  
  4542. Accidental following may be turned on or off as needed.  When
  4543. turned off, accidentals no longer carry throughout the measure as
  4544. in traditional notation.  This convention is sometimes used in
  4545. contemporary scores.
  4546.  
  4547.      !accidentals "off"
  4548.  
  4549. Octave Following
  4550.  
  4551. Turning off octave following indicates that pitches stay in the
  4552. same absolute octave register until explicitly moved. An absolute
  4553. octave starts at pitch c and ends at the b above it.  The octave
  4554. middle-c-to-b is indicated with an equals sign (`=') and octave
  4555. displacement is indicated with the appropriate number of commas
  4556. or apostrophes.  These displacements are cummulative.  For
  4557. example,
  4558.  
  4559.      !octaves "off"
  4560.      4='c g b 'c
  4561.  
  4562. starts at the c above middle c and ends at two c's above middle
  4563. c.
  4564.  
  4565. Vertical Following
  4566.  
  4567. Turning off vertical following means that durations, register,
  4568. and parameters only carry horizontally from note to note and not
  4569. vertically as described in the section on divisi.
  4570.  
  4571.      !vertical "off"
  4572.  
  4573. Transposition
  4574.  
  4575. Any instrument part can be transposed to another key by
  4576. indicating the intervalic difference between the notated key and
  4577. the desired key.  This difference is always taken with reference
  4578. to middle c - to transpose a whole step upward, for example, type
  4579.  
  4580.      !transpose "d"
  4581.  
  4582. This indicates that the part is transposed by the interval
  4583. difference between middle c and d.
  4584.  
  4585.  
  4586. Next-value and Previous-value Parameteres
  4587.  
  4588. In order to play a note, it is sometimes necessary for an
  4589. instrument to know what value one or more parameters will have
  4590. for the next note.  For instance, an instrument might be designed
  4591. which glisses during the last portion of its performance (perhaps
  4592. only when a slur is indicated) from its written pitch to the
  4593. pitch of the next note.  This can only be done, of course, if the
  4594. instrument can know what the pitch of the next note will be.
  4595.  
  4596. The necessary information can be provided using next-value
  4597. parameters.  A next value parameter might be declared by
  4598.  
  4599.      !next p5 "p6"
  4600.  
  4601. which is interpreted to mean that for the current instrument, p6
  4602. will contain the next note's p5 value. This holds true globally
  4603. for all occurences of this instrument until further
  4604. modifications.  If for any reason you wish to override this
  4605. value, p6 may be filled in explicitly.  This is sometimes useful
  4606. for the last note of a section, for which p6 will otherwise
  4607. assume the p5 value for the current note.  The next-value feature
  4608. is illustrated in the Scot example II.
  4609.  
  4610. The necessary information may also be provided using standard
  4611. numeric score next-value parameters.  A parameter argument
  4612. containing the symbol npx (where x is an integer) will substitute
  4613. parameter number x of the following note for that instrument. 
  4614. Similarly, the value of a parameter occurring during the previous
  4615. note may be referenced with the symbol ppx (where x is an
  4616. integer).  Details of the next- and previous-value parameter
  4617. feature may be found in the Numeric Scores section.
  4618.  
  4619. Ramping
  4620.  
  4621. Pfields containing the symbol < will be replaced by values
  4622. derived from linear interpolation of a time-based ramp.  Ramp
  4623. endpoints are defined by the first real number found in the same
  4624. pfield of a preceding and following note played by the same
  4625. instrument.  Details of the ramping feature are likewise found in
  4626. the Numeric Scores section.
  4627.  
  4628. f0 Statements
  4629.  
  4630. In each score section, Scot automatically produces an f0
  4631. statement with a p2 equal to the ending time of the last note or
  4632. rest in the section.  Thus, `dead time' at the end of a section
  4633. for reverberation decay or whatever purpose may be specified
  4634. musically by rests in one or more parts.  See the eighth rest at
  4635. the end of Scot example II and its output score shown below.
  4636.  
  4637.  
  4638. Output Scores
  4639.  
  4640. Output file score from Scot Example I.
  4641.  
  4642.      f1 0 512 10 1 .5 .25 .126
  4643.      f2 0 256  7 1 120 1 8 0 128 1
  4644.      i1.01 0 1 0 8.00
  4645.      i1.01 1 0.5 0 8.02
  4646.      i1.01 1.5 0.5 0 8.03
  4647.      i1.01 2 0.5 0 8.05
  4648.      i1.01 3 1 0 9.00
  4649.      i1.01 4 0.75 0 8.10
  4650.      i1.01 4.75 0.25 0 8.09
  4651.      i1.01 5 0.25 0 8.08
  4652.      i1.01 5.25 0.25 0 8.07
  4653.      i1.01 5.5 0.25 0 8.06
  4654.      i1.01 5.75 0.25 0 8.05
  4655.      i1.01 6 1 0 8.03
  4656.      i1.01 7 1 0 8.00
  4657.      i2.01 0 2 0 6.00
  4658.      i2.01 2 2 0 6.08
  4659.      i2.01 4 2 0 6.07
  4660.      i2.01 6 2 0 7.00
  4661.      t0 60
  4662.      f0 8
  4663.      s
  4664.      i1.01 0 0.6667 0 9.00
  4665.      i1.01 1.3333 0.6667 0 9.00
  4666.      i1.01 2 1.75 0 9.02
  4667.      i1.01 3.75 0.25 0 9.03
  4668.      i1.01 4 0.6667 0 9.05
  4669.      i1.01 5.3333 0.6667 0 9.05
  4670.      i1.01 6 1.75 0 9.07
  4671.      i1.01 7.75 0.25 0 9.09
  4672.      i2.01 0 1 0 6.00
  4673.      i2.01 1 1 0 6.07
  4674.      i2.01 2 1 0 6.00
  4675.      i2.01 3 1 0 6.07
  4676.      i2.01 4 2 0 7.08
  4677.      i2.01 6 2 0 7.07
  4678.      t0 60
  4679.      f0 8
  4680.      s
  4681.  
  4682.  
  4683.  
  4684. Output file score from Scot Example II.
  4685.  
  4686.      f1 0 256 10 1
  4687.      c r1 n 7 5
  4688.      c r1 n 8 6
  4689.      i1.01 0.5000 0.5000 0 8.00 3 8.00 3
  4690.      i1.02 0.5000 0.5000 0 8.04 3 8.05 3
  4691.      i1.03 0.5000 0.5000 0 8.07 3 8.09 3
  4692.      i1.01 1.5000 0.5000 0 8.00 3 8.01 3
  4693.      i1.02 1.5000 0.5000 0 8.05 3 8.07 3
  4694.      i1.03 1.5000 0.5000 0 8.09 3 8.10 3
  4695.      i1.01 2.5000 0.5000 0 8.01 3 8.00 5
  4696.      i1.02 2.5000 0.5000 0 8.07 3 8.05 5
  4697.      i1.03 2.5000 0.5000 0 8.10 3 8.09 5
  4698.      i1.01 3.5000 0.5000 0 8.00 5 8.02 5
  4699.      i1.02 3.5000 0.5000 0 8.05 5 8.05 5
  4700.      i1.01 4.0000 1.0000 1 8.02 5 8.00 5
  4701.      i1.03 3.5000 1.0000 0 8.09 5 8.07 5
  4702.      i1.01 5.0000 1.0000 2 8.00 5 8.00 5
  4703.      i1.02 4.0000 1.5000 0 8.05 5 8.04 5
  4704.      i1.02 5.5000 0.5000 0 8.04 5 8.05 5
  4705.      i1.03 4.5000 1.5000 0 8.07 5 8.05 5
  4706.      i1.01 6.0000 1.5000 0 8.00 5 8.00 5
  4707.      i1.02 6.0000 1.5000 0 8.05 5 8.05 5
  4708.      i1.03 6.0000 1.5000 0 8.05 5 8.05 5
  4709.      c r2 n 7 5
  4710.      c r2 n 8 6
  4711.      i2.01 0.0000 0.5000 0 7.00 3 7.05 3
  4712.      i2.01 1.0000 0.5000 0 7.05 3 7.04 3
  4713.      i2.01 2.0000 0.5000 0 7.04 3 7.05 3
  4714.      i2.01 3.0000 0.5000 0 7.05 3 7.10 5
  4715.      i2.01 4.0000 2.0000 1 7.10 5 7.09 5
  4716.      i2.02 4.0000 1.0000 1 6.10 5 7.00 5
  4717.      i2.02 5.0000 1.0000 2 7.00 5 7.05 5
  4718.      i2.01 6.0000 1.5000 2 7.09 5 7.09 5
  4719.      i2.02 6.0000 1.5000 0 7.05 5 7.05 5
  4720.      t0 60 0.0000 90.0000 2.0000 90.0000 4.0000 80.0000 4.0000
  4721. 90.0000
  4722.      f0 8.0000
  4723.      s
  4724.      e
  4725.  
  4726.  
  4727. 6. The Unix CSOUND Command
  4728.  
  4729.  
  4730. csound is a command for passing an orchestra file and score file
  4731. to Csound to generate a soundfile.  The score file can be in one
  4732. of many different formats, according to user preference. 
  4733. Translation, sorting, and formatting into orchestra-readable
  4734. numeric text is handled by various preprocessors; all or part of
  4735. the score is then sent on to the orchestra.  Orchestra
  4736. performance is influenced by command flags, which set the level
  4737. of displays and console reports, specify 1/0 filenames and sample
  4738. formats, and declare the nature of realtime sensing and control.  
  4739.  
  4740. The format of a command is: 
  4741.  
  4742.           csound [-flags] orchname scorename 
  4743.  
  4744. where the arguments are of 2 types: flag arguments (beginning
  4745. with a "-"), and name arguments (such as filenames).  Certain
  4746. flag arguments take a following name or numeric argument.  The
  4747. available flags are: 
  4748.  
  4749.           -I, -n                   sound output inhibitors 
  4750.           -iName, -oName           sound I/O filenames 
  4751.           -bNumb, -BNumb, -h       audio buffers & header control 
  4752.           -A, -c, -a, -u, -s, -1, -f    audio output formats 
  4753.           -v, -mNumb, -d, -g       message & display levels 
  4754.           -S, -xName, -tNumb       score formats & tempo control
  4755.           -LName                   line-oriented realtime event stream
  4756.           -MName, -FName, -PNumb   MIDI event streams
  4757.           -N, -T                   notify or terminate when done
  4758.  
  4759. Flags may appear anywhere in the command line, either separately
  4760. or bundled together.  A flag taking a Name or Number will find it
  4761. in that argument, or in the immediately subsequent one.  The
  4762. following are thus equivalent commands: 
  4763.  
  4764.           csound  -nm3  orchname  -Sxxfilename  scorename 
  4765.           csound  -n  -m  3  orchname  -x  xfilename  -S scorename 
  4766.  
  4767. All flags and names are optional.  The default values are: 
  4768.  
  4769.           csound  -s  -otest  -b1024  -B1024  -m7  -P128  orchname  scorename 
  4770.  
  4771.           where orchname is a file containing Csound orchestra code, 
  4772.  
  4773. and scorename is a file of score data in standard numeric score
  4774. format, optionally presorted and time-warped.  If scorename is
  4775. omitted, there are two default options:  1)  if realtime input is
  4776. expected (-L, -M or -F), a dummy scorefile is substituted
  4777. consisting of the single statement  'f 0 3600'  (i.e. listen for
  4778. RT input for one hour);  2)  else csound uses the previously
  4779. processed score.srt  in the current directory.  
  4780.  
  4781. Csound reports on the various stages of score and orchestra
  4782. processing as it goes, doing various syntax and error checks
  4783. along the way.  Once the actual performance has begun, any error
  4784. messages will derive from either the instrument loader or the
  4785. unit generators themselves.  A csound command may include any
  4786. rational combination of the following flag arguments, with
  4787. default values as described: 
  4788.  
  4789.  
  4790. csound -I 
  4791. I-time only.  Allocate and initialize all instruments as per the
  4792. score, but skip all P-time processing (no k-signals or a-signals,
  4793. and thus no amplitudes and no sound).  Provides a fast validity
  4794. check of the score pfields and orchestra i-variables.  
  4795.  
  4796. csound -n 
  4797. Nosound.  Do all processing, but bypass writing of sound to disk. 
  4798. This flag does not change the execution in any other way.  
  4799.  
  4800. csound -i  isfname 
  4801. Input soundfile name.  If not a full pathname, the file will be
  4802. sought first in the current directory, then in that given by the
  4803. environment variable SSDIR (if defined), then by SFDIR.  The name
  4804. stdin will cause audio to be read from standard input.  If
  4805. RTAUDIO is enabled, the name devaudio will request sound from the
  4806. host audio input device.  
  4807.  
  4808. csound -o osfname 
  4809. Output soundfile name.  If not a full pathname, the soundfile
  4810. will be placed in the directory given by the environment variable
  4811. SFDIR (if defined), else in the current directory.  The name
  4812. stdout will cause audio to be written to standard output.  If no
  4813. name is given, the default name will be test.  If RTAUDIO is
  4814. enabled, the name devaudio will send to the host audio output
  4815. device. 
  4816.  
  4817. csound -b Numb 
  4818. Number of audio sample-frames per soundio software buffer.  Large
  4819. is efficient, but small will reduce audio I/O delay.  The default
  4820. is 1024.  In realtime performance, Csound waits on audio I/O on
  4821. Numb boundaries.  It also processes audio (and polls for other
  4822. input like MIDI) on orchestra ksmps boundaries.  The two can be
  4823. made synchronous.  For convenience, if Numb = -N (is negative)
  4824. the effective value is ksmps * N  (audio synchronous with
  4825. k-period boundaries).  With N small  (e.g. 1) polling is then
  4826. frequent and also locked to fixed DAC sample boundaries.
  4827.  
  4828. csound -B Numb 
  4829. Number of audio sample-frames held in the DAC hardware buffer. 
  4830. This is a threshold on which software audio I/O (above) will wait
  4831. before returning.  A small number reduces audio I/O delay;  but
  4832. the value is often hardware limited, and small values will risk
  4833. data lates.  The default is 1024.
  4834.  
  4835. csound -h 
  4836. No header on output soundfile.  Don't write a file header, just
  4837. binary samples.  
  4838.  
  4839. csound {-c, -a, -u, -s, -l, -f} 
  4840. Audio sample format of the output soundfile.  One of: 
  4841.      c    8-bit signed character 
  4842.      a    8-bit a-law 
  4843.      u    8-bit u-law 
  4844.      s    short integer 
  4845.      l    long integer 
  4846.      f    single-precision float (not playable, but can be read
  4847.           by -i, soundin and GEN01) 
  4848.  
  4849. csound -A 
  4850. Write an AIFF output soundfile.   Restricts the above formats to
  4851. c, s, or l. 
  4852.  
  4853. csound -v 
  4854. Verbose translate and run.  Prints details of orch translation
  4855. and performance, enabling errors to be more clearly located.
  4856.  
  4857.  
  4858. csound -m Numb 
  4859. Message level for standard (terminal) output.  Takes the sum of 3
  4860. print control flags, turned on by the following values: 1 = note
  4861. amplitude messages, 2 = samples out of range message, 4 = warning
  4862. messages.  The default value is m7 (all messages on).
  4863.  
  4864. csound -d 
  4865. Suppress all displays.  
  4866.  
  4867. csound -g 
  4868. Recast graphic displays into ascii characters, suitable for any
  4869. terminal.  
  4870.  
  4871. csound -S 
  4872. Interpret scorename as a Scot file and create a standard score
  4873. file (named "score") from it, then sort and perform that.
  4874.  
  4875. csound -x xfile 
  4876. Extract a portion of the sorted score score.srt, according to
  4877. xfile (see extract below).
  4878.  
  4879. csound -t Numb
  4880. Use the uninterpreted beats of score.srt for this performance,
  4881. and set the initial tempo at Numb beats per minute.  When this
  4882. flag is set, the tempo of score performance is also controllable
  4883. from within the orchestra (see the tempo unit).
  4884.  
  4885. csound -L devname 
  4886. Read Line-oriented realtime score events from device devname. 
  4887. The name stdin will permit score events to be typed at your
  4888. terminal, or piped from another process.  Each line-event is
  4889. terminated by a carriage-return.  Events are coded just like
  4890. those in a standard numeric score, except that an event with p2=0
  4891. will be performed immediately, and an event with p2=T will be
  4892. performed T seconds after arrival.  Events can arrive at any
  4893. time, and in any order.  The score carry feature is legal here,
  4894. as are held notes (p3 negative) and string arguments, but ramps
  4895. and pp or np references are not.
  4896.  
  4897. csound -M devname 
  4898. Read MIDI events from device devname.
  4899.  
  4900. csound -F mfname 
  4901. Read MIDI events from midifile mfname.
  4902.  
  4903. csound -P Numb 
  4904. Set MIDI sustain pedal threshold (0 - 128).  The official switch
  4905. value of 64 is normally too low, and is more realistic above 100. 
  4906. The default value of 128 will block all pedal info.
  4907.  
  4908. csound -N 
  4909. Notify (ring the bell) when score or miditrack is done.
  4910.  
  4911. csound -T 
  4912. Terminate the performance when miditrack is done.
  4913.  
  4914.  
  4915.  
  4916. The EXTRACT feature
  4917.  
  4918. This feature will extract a segment of a sorted numeric score
  4919. file according to instructions taken from a control file.  The
  4920. control file contains an instrument list and two time points,
  4921. from and to, in the form: 
  4922.  
  4923.           instruments 1  2  from  1:27.5  to  2:2 
  4924.  
  4925. The component labels may be abbreviated as i, f and t.  The time
  4926. points denote the beginning and end of the extract in terms of: 
  4927.  
  4928.           [section no.] : [beat no.].  
  4929.  
  4930. each of the three parts is also optional.  The default values for
  4931. missing i, f or t are: 
  4932.  
  4933.           all instruments, beginning of score, end of score.
  4934.  
  4935. extract reads an orchestra-readable score file and produces an
  4936. orchestra-readable result.  Comments, tabs and extra spaces are
  4937. flushed, w and a statements are added and an f0 reflecting the
  4938. extract length is appended to the output.  Following an extract
  4939. process, the abbreviated score will contain all function table
  4940. statements, together with just those note statements that occur
  4941. in the from-to interval specified.  Notes lying completely in the
  4942. interval will be unmodified; notes that lie only partly within
  4943. will have their p3 durations truncated as necessary.
  4944.  
  4945.  
  4946. Independent Preprocessing
  4947.  
  4948. Although the result of all score preprocessing is retained in the
  4949. file score.srt after orchestra performance (it exists as soon as
  4950. score preprocessing has completed), the user may sometimes want
  4951. to run these phases independently.  The command 
  4952.  
  4953.           scot filename 
  4954.  
  4955. will process the Scot formatted filename, and leave a standard
  4956. numeric score result in a file named score for perusal or later
  4957. processing.
  4958.  
  4959. The command 
  4960.           scscort < infile > outfile 
  4961.  
  4962. will put a numeric score infile through Carry, Tempo, and Sort
  4963. preprocessing, leaving the result in outfile.  
  4964.  
  4965. Likewise extract, also normally invoked as part of the csound
  4966. command, can be invoked as a standalone program: 
  4967.  
  4968.           extract xfile < score.sort > score.extract 
  4969.  
  4970. This command expects an already sorted score.  An unsorted score
  4971. should first be sent through scsort then piped to the extract
  4972. program: 
  4973.  
  4974.           scsort < scorefile | extract xfile > score.extract 
  4975.  
  4976.  
  4977. Appendix 1: The Soundfile Utility Programs
  4978.  
  4979.  
  4980.  
  4981. The Csound Utilities are soundfile preprocessing programs that
  4982. return information on a soundfile or create some analyzed version
  4983. of it for use by certain Csound generators.  Though different in
  4984. goals, they share a common soundfile access mechanism and are
  4985. describable as a set.  The Soundfile Utility programs can be
  4986. invoked in two equivalent forms:
  4987.  
  4988.           csound -U utilname  [flags]  filenames  . . .
  4989.           utilname  [flags]  filenames  . . .
  4990.  
  4991. In the first, the utility is invoked as part of the Csound
  4992. executable, while in the second it is called as a standalone
  4993. program.  The second is smaller by about 200K, but the two forms
  4994. are identical in function.  The first is convenient in not
  4995. requiring the maintenance and use of several independent
  4996. programsעone program does all.  When using this form, a -U flag
  4997. detected in the command line will cause all subsequent flags and
  4998. names to be interpreted as per the named utility;  i.e. Csound
  4999. generation will not occur, and the program will terminate at the
  5000. end of utility processing.
  5001.  
  5002. Directories.  Filenames are of two kinds, source soundfiles and
  5003. resultant analysis files.  Each has a hierarchical naming
  5004. convention, influenced by the directory from which the Utility is
  5005. invoked.  Source soundfiles with a full pathname (begins with dot
  5006. (.), slash (/), or for ThinkC includes a colon (:)), will be
  5007. sought only in the directory named.  Soundfiles without a path
  5008. will be sought first in the current directory, then in the
  5009. directory named by the SSDIR environment variable (if defined),
  5010. then in the directory named by SFDIR.  An unsuccessful search
  5011. will return a "cannot open" error.
  5012.  
  5013. Resultant analysis files are written into the current directory,
  5014. or to the named directory if a path is included.  It is tidy to
  5015. keep analysis files separate from sound files, usually in a
  5016. separate directory known to the SADIR variable.  Analysis is
  5017. conveniently run from within the SADIR directory.  When an
  5018. analysis file is later invoked by a Csound generator (adsyn,
  5019. lpread, pvoc) it is sought first in the current directory, then
  5020. in the directory defined by SADIR.
  5021.  
  5022. Soundfile Formats.  Csound can read and write audio files in a
  5023. variety of formats.  Write formats are described by Csound
  5024. command flags.  On reading, the format is determined from the
  5025. soundfile header, and the data automatically converted to
  5026. floating-point during internal processing.  When Csound is
  5027. installed on a host with local soundfile conventions (SUN, NeXT,
  5028. Macintosh) it may conditionally include local packaging code
  5029. which creates soundfiles not portable to other hosts.  However,
  5030. Csound on any host can always generate and read AIFF files, which
  5031. is thus a portable format.  Sampled sound libraries are typically
  5032. AIFF, and the variable SSDIR usually points to a directory of
  5033. such sounds.  If defined, the SSDIR directory is in the search
  5034. path during soundfile access.  Note that some AIFF sampled sounds
  5035. have an audio looping feature for sustained performance;  the
  5036. analysis programs will traverse any loop segment once only.
  5037.  
  5038. For soundfiles without headers, an SR value may be supplied by a
  5039. command flag (or its default).  If both header and flag are
  5040. present, the flag value will over-ride.  
  5041.  
  5042. When sound is accessed by the audio Analysis programs (below),
  5043. only a single channel is read.  For stereo or quad files, the
  5044. default is channel one;  alternate channels may be obtained on
  5045. request.
  5046.  
  5047.  
  5048. SNDINFO -  get basic information about one or more soundfiles.
  5049.  
  5050.  
  5051.      csound -U sndinfo  soundfilenames  . . .
  5052. or   sndinfo   soundfilenames  . . .
  5053.  
  5054. sndinfo will attempt to find each named file, open it for
  5055. reading, read in the soundfile header, then print a report on the
  5056. basic information it finds.  The order of search across soundfile
  5057. directories is as described above.  If the file is of type AIFF,
  5058. some further details are listed first.
  5059.  
  5060. EXAMPLE
  5061.  
  5062.      csound -U sndinfo  test  Bosendorfer/"BOSEN mf A0 st"  foo 
  5063. foo2
  5064.  
  5065. where the environment variables SFDIR = /u/bv/sound, and SSDIR =
  5066. /so/bv/Samples, might produce the following:
  5067.  
  5068.      util  SNDINFO:
  5069.      
  5070.      /u/bv/sound/test:
  5071.           srate 22050, monaural, 16 bit shorts, 1.10 seconds
  5072.           headersiz 1024, datasiz 48500  (24250 sample frames)
  5073.  
  5074. /so/bv/Samples/Bosendorfer/BOSEN mf A0 st:  AIFF, 197586 stereo
  5075. samples, base Frq 261.6 (midi 60), sustnLp: mode 1, 121642 to
  5076. 197454, relesLp: mode 0
  5077.      AIFF soundfile, looping with modes 1, 0
  5078.      srate 44100, stereo, 16 bit shorts, 4.48 seconds
  5079.      headersiz  402, datasiz 790344  (197586 sample frames)
  5080.  
  5081.      /u/bv/sound/foo:
  5082.           no recognizable soundfile header
  5083.  
  5084.      /u/bv/sound/foo2:
  5085.           couldn't find
  5086.  
  5087. HETRO -  hetrodyne filter analysis for the Csound adsyn
  5088. generator.
  5089.  
  5090.  
  5091.      csound -U hetro  [flags]  infilename  outfilename
  5092. or   hetro  [flags]  infilename  outfilename
  5093.  
  5094. hetro takes an input soundfile, decomposes it into component
  5095. sinusoids, and outputs a description of the components in the
  5096. form of breakpoint amplitude and frequency tracks.  Analysis is
  5097. conditioned by the control flags below.  A space is optional
  5098. between flag and value.
  5099.  
  5100. -s<srate> sampling rate of the audio input file.  This will
  5101. over-ride the srate of the soundfile header, which otherwise
  5102. applies.   If neither is present, the default is 10000.  Note
  5103. that for adsyn synthesis the srate of the source file and the
  5104. generating orchestra need not be the same.
  5105.  
  5106. -c<channel>    channel number sought.  The default is 1.
  5107.  
  5108. -b<begin> beginning time (in seconds) of the audio segment to be
  5109. analyzed.  The default is 0.0
  5110.  
  5111. -d<duration>   duration (in seconds) of the audio segment to be
  5112. analyzed.  The default of 0.0 means to the end of the file. 
  5113. Maximum length is 32.766 seconds.
  5114.  
  5115. -f<begfreq>    estimated starting frequency of the fundamental,
  5116. necessary to initialize the filter analysis.  The default is 100
  5117. (cps).
  5118.  
  5119. -h<partials>   number of harmonic partials sought in the audio
  5120. file.  Default is 10, maximum 50.
  5121.  
  5122. -M<maxamp> maximum amplitude summed across all concurrent tracks. 
  5123. The default is 32767.
  5124.  
  5125. -m<minamp>     amplitude threshold below which a single pair of
  5126. amplitude/frequency tracks is considered dormant and will not
  5127. contribute to output summation.  Typical values:  128 (48 db down
  5128. from full scale), 64 (54 db down), 32 (60 db down), 0 (no
  5129. thresholding).  The default threshold is 64 (54 db down).
  5130.  
  5131. -n<brkpts>     initial number of analysis breakpoints in each
  5132. amplitude and frequency track, prior to thresholding (-m) and
  5133. linear breakpoint consolidation.  The initial points are spread
  5134. evenly over the duration.  The default is 256.
  5135.  
  5136. -l<cutfreq>    substitute a 3rd order Butterworth low-pass filter
  5137. with cutoff frequency cutfreq (in cps), in place of the default
  5138. averaging comb filter.  The default is 0 (don't use).
  5139.  
  5140. EXAMPLE
  5141.           hetro     -s44100  -b.5  -d2.5  -h16  -M24000 audiofile.test  adsynfile7
  5142.  
  5143. This will analyze 2.5 seconds of channel 1 of a file
  5144. "audiofile.test", recorded at 44.1 KHz, beginning .5 seconds from
  5145. the start, and place the result in a file "adsynfile7".  We
  5146. request just the first 16 harmonics of the sound, with 256
  5147. initial breakpoint values per amplitude or frequency track, and a
  5148. peak summation amplitude of 24000.  The fundamental is estimated
  5149. to begin at 100 Hz.  Amplitude thresholding is at 54 db down. 
  5150. The Butterworth LPF is not enabled.
  5151.  
  5152. FILE FORMAT
  5153.      The output file contains time-sequenced amplitude and
  5154. frequency values for each partial of an additive complex audio
  5155. source.  The information is in the form of breakpoints (time,
  5156. value, time, value, ....) using 16-bit integers in the range 0 -
  5157. 32767.  Time is given in milliseconds, and frequency in Hertz
  5158. (cps).  The breakpoint data is exclusively non-negative, and the
  5159. values -1 and -2 uniquely signify the start of new amplitude and
  5160. frequency tracks.  A track is terminated by the value 32767. 
  5161. Before being written out, each track is data-reduced by amplitude
  5162. thresholding and linear breakpoint consolidation. 
  5163.  
  5164. A component partial is defined by two breakpoint sets:  an
  5165. amplitude set, and a frequency set.  Within a composite file
  5166. these sets may appear in any order (amplitude, frequency,
  5167. amplitude ....;  or amplitude, amplitude..., then frequency,
  5168. frequency,...).  During adsyn resynthesis the sets are
  5169. automatically paired (amplitude, frequency) from the order in
  5170. which they were found.  There should be an equal number of each.
  5171.  
  5172. A legal adsyn control file could have following format:
  5173.  
  5174. -1  time1  value1  ...   timeK  valueK   32767    ; amplitude breakpoints for partial 1
  5175. -2  time1  value1  ...   timeL   valueL   32767   ; frequency breakpoints for partial 1
  5176. -1  time1  value1  ...   timeM  valueM  32767     ; amplitude breakpoints for partial 2
  5177. -2  time1  value1  ...   timeN   valueN  32767    ; frequency breakpoints for partial 2
  5178. -2  time1  value1  ..........
  5179. -2  time1  value1  ..........                ; pairable tracks for partials 3 and 4
  5180. -1  time1  value1  ..........
  5181. -1  time2  value1  ..........
  5182.  
  5183.  
  5184. LPANAL - linear predictive analysis for the Csound lp generators
  5185.  
  5186.  
  5187.      csound -U lpanal   [flags]   infilename   outfilename
  5188. or   lpanal   [flags]   infilename   outfilename
  5189.  
  5190. lpanal performs both lpc and pitch-tracking analysis on a
  5191. soundfile to produce a time-ordered sequence of frames of control
  5192. information suitable for Csound resynthesis.  Analysis is
  5193. conditioned by the control flags below.  A space is optional
  5194. between the flag and its value.
  5195.  
  5196. -s<srate> sampling rate of the audio input file.  This will
  5197. over-ride the srate of the soundfile header, which otherwise
  5198. applies.   If neither is present, the default is 10000.
  5199.  
  5200. -c<channel>    channel number sought.  The default is 1.
  5201.  
  5202. -b<begin> beginning time (in seconds) of the audio segment to be
  5203. analyzed.  The default is 0.0
  5204.  
  5205. -d<duration>   duration (in seconds) of the audio segment to be
  5206. analyzed.  The default of 0.0 means to the end of the file.
  5207.  
  5208. -p<npoles>     number of poles for analysis.  The default is 34,
  5209. the maximum 50.
  5210.  
  5211. -h<hopsize>    hop size (in samples) between frames of analysis. 
  5212. This determines the number of frames per second (srate / hopsize)
  5213. in the output control file.  The analysis framesize is hopsize *
  5214. 2 samples.  The default is 200, the maximum 500.
  5215.  
  5216. -C<string>     text for the comments field of the lpfile header. 
  5217. The default is the null string.
  5218.  
  5219. -P<mincps>     lowest frequency (in cps) of pitch tracking.  -P0
  5220. means no pitch tracking.
  5221.  
  5222. -Q<maxcps>     highest frequency (in cps) of pitch tracking.  The
  5223. narrower the pitch range, the more accurate the pitch estimate. 
  5224. The defaults are -P70, -Q200.
  5225.  
  5226. -v<verbosity> level of terminal information during analysis.  0 =
  5227. none,  1 = verbose, 2 = debug. The default is 0.
  5228.  
  5229. EXAMPLE
  5230.           lpanal  -p26  -d2.5  -P100  -Q400  audiofile.test 
  5231. lpfil22
  5232.  
  5233. will analyze the first 2.5 seconds of file "audiofile.test",
  5234. producing srate/200 frames per second, each containing 26-pole
  5235. filter coefficients and a pitch estimate between 100 and 400
  5236. Hertz.  Output will be placed in "lpfil22" in the current
  5237. directory.
  5238.  
  5239. FILE FORMAT
  5240.      Output is a file comprised of an identifiable header plus a
  5241. set of frames of floating point analysis data.  Each frame
  5242. contains four values of pitch and gain information, followed by
  5243. npoles filter coefficients.  The file is readable by Csound's
  5244. lpread.
  5245.  
  5246.      lpanal is an extensive modification of Paul Lanksy's lpc
  5247. analysis programs.
  5248.  
  5249.  
  5250. PVANAL - Fourier analysis for the Csound pvoc generator
  5251.  
  5252.  
  5253.      csound -U pvanal   [flags]   infilename   outfilename
  5254. or   pvanal   [flags]   infilename   outfilename
  5255.  
  5256. pvanal converts a soundfile into a series of short-time Fourier
  5257. transform (STFT) frames at regular timepoints (a frequency-domain
  5258. representation).  The output file can be used by pvoc to generate
  5259. audio fragments based on the original sample, with timescales and
  5260. pitches arbitrarily and dynamically modified.  Analysis is
  5261. conditioned by the flags below.  A space is optional between the
  5262. flag and its argument.
  5263.  
  5264. -s<srate> sampling rate of the audio input file.  This will
  5265. over-ride the srate of the soundfile header, which otherwise
  5266. applies.   If neither is present, the default is 10000.
  5267.  
  5268. -c<channel>    channel number sought.  The default is 1.
  5269.  
  5270. -b<begin> beginning time (in seconds) of the audio segment to be
  5271. analyzed.  The default is 0.0
  5272.  
  5273. -d<duration>   duration (in seconds) of the audio segment to be
  5274. analyzed.  The default of 0.0 means to the end of the file.
  5275.  
  5276. -n<frmsiz>     STFT frame size, the number of samples in each
  5277. Fourier analysis frame.  Must be a power of two, in the range 16
  5278. to 16384.  For clean results, a frame must be larger than the
  5279. longest pitch period of the sample.  However, very long frames
  5280. result in temporal "smearing" or reverberation.  The bandwidth of
  5281. each STFT bin is determined by sampling rate / frame size.  The
  5282. default framesize is the smallest power of two that corresponds
  5283. to more than 20 milliseconds of the source (e.g. 256 points at 10
  5284. kHz sampling, giving a 25.6 ms frame).
  5285.  
  5286. -w<windfact> Window overlap factor.  This controls the number of
  5287. Fourier transform frames per second.  Csound's pvoc will
  5288. interpolate between frames, but too few frames will generate
  5289. audible distortion;  too many frames will result in a huge
  5290. analysis file.  A good compromise for windfact is 4, meaning that
  5291. each input point occurs in 4 output windows, or conversely that
  5292. the offset between successive STFT frames is framesize/4.  The
  5293. default value is 4.  Do not use this flag with -h.
  5294.  
  5295. -h<hopsize>  STFT frame offset.  Converse of above, specifying
  5296. the increment in samples between successive frames of analysis
  5297. (see also lpcanal).  Do not use with -w.
  5298.  
  5299. EXAMPLE
  5300.           pvanal  asound  pvfile
  5301.  
  5302. will analyze the soundfile "asound" using the default frmsiz and
  5303. windfact to produce the file "pvfile" suitable for use with pvoc.
  5304.  
  5305. FILES
  5306.      The output file has a special pvoc header containing details
  5307. of the source audio file, the analysis frame rate and overlap. 
  5308. Frames of analysis data are stored as float, with the magnitude
  5309. and 'frequency' (in Hz) for the first N/2 + 1 Fourier bins of
  5310. each frame in turn.  'Frequency' encodes the phase increment in
  5311. such a way that for strong harmonics it gives a good indication
  5312. of the true frequency.  For low amplitude or rapidly moving
  5313. harmonics it is less meaningful.
  5314.  
  5315. DIAGNOSTICS
  5316.      Prints total number of frames, and frames completed on every
  5317. 20th.
  5318.  
  5319. AUTHOR:   Dan Ellis, dpwe@media-lab.media.mit.edu
  5320.  
  5321. Appendix 2:  CSCORE
  5322.  
  5323.  
  5324. Cscore is a standalone program for generating and manipulating
  5325. numeric score files.  It comprises a number of function
  5326. subprograms, called into operation by a user-written main
  5327. program.  The function programs augment the C language library
  5328. functions;  they can optionally read standard numeric score
  5329. files, can massage and expand the data in various ways, then
  5330. write the data out as a new score file to be read by a Csound
  5331. orchestra.
  5332.  
  5333. The user-written main program is also in C.  It is not essential
  5334. to know the C language well to write a main program, since the
  5335. function calls have a simple syntax, and are powerful enough to
  5336. do most of the complicated work.  Additional power can come from
  5337. C later as the need arises.
  5338.  
  5339. Events, Lists, and Operations
  5340.  
  5341. An event in Cscore is equivalent to one statement of a standard
  5342. numeric score.  It is either created or read in from an existing
  5343. score file.  An event is comprised of an opcode and an array of
  5344. pfield values stored somewhere in memory.  Storage is organized
  5345. by the following structure:
  5346.  
  5347.      struct event {
  5348.           char op;            /* opcode */
  5349.           char tnum;
  5350.           short pcnt;
  5351.           float p[PMAX+1];         /* pfields */
  5352.      };
  5353.  
  5354. Any function subprogram that creates, reads, or copies an event
  5355. function will return a pointer to the storage structure holding
  5356. the event data.  The event pointer can be used to access any
  5357. component of the structure, in the form of e->op or e->p[n]. 
  5358. Each newly stored event will give rise to a new pointer, and a
  5359. sequence of new events will generate a sequence of distinct
  5360. pointers that must themselves be stored.  Groups of event
  5361. pointers are stored in a list, which has its own structure:
  5362.  
  5363.      struct evlist {
  5364.           int nslots;         /* size of this list      */
  5365.           struct event *e[1];      /* list of event pointers */
  5366.      };
  5367.  
  5368. Any function that creates or modifies a list will return a
  5369. pointer to the new list.  The list pointer can be used to access
  5370. any of its component event pointers, in the form of a->e[n]. 
  5371. Event pointers and list pointers are thus primary tools for
  5372. manipulating the data of a score file.
  5373.  
  5374. Pointers and lists of pointers can be copied and reordered
  5375. without modifying the data values they refer to.  This means that
  5376. notes and phrases can be copied and manipulated from a high level
  5377. of control.  Alternatively, the data within an event or group of
  5378. events can be modified without changing the event or list
  5379. pointers.  Cscore provides a library of programming methods or
  5380. function subprograms by which scores can be created and
  5381. manipulated in this way.  
  5382.  
  5383. In the following summary of Cscore function calls, some simple
  5384. naming conventions are used:
  5385.  
  5386.      the symbols e, f are pointers to events (notes);
  5387.      the symbols a, b are pointers to lists (arrays) of such
  5388. events;
  5389.      the letters ev at the end of a function name signify
  5390. operation on an event;
  5391.      the letter l at the start of a function name signifies
  5392. operation on a list.
  5393.  
  5394.          calling syntax           description
  5395.  
  5396.      e = createv(n);          create a blank event with n pfields
  5397.      e = defev("...");        defines an event as per the character string ...
  5398.      e = copyev(f);           make a new copy of event f
  5399.      e = getev();             read the next event in the score input file
  5400.      putev(e);                write event e to the score output file
  5401.      putstr("...");           write the character string ... to score output
  5402.  
  5403.      a = lcreat(n);           create an empty event list with n slots
  5404.      a = lappev(a,e);         append event e to list a
  5405.      n = lcount(a);           count the events now in list a
  5406.      a = lcopy(b);            copy the list b (but not the events)
  5407.      a = lcopyev(b);          copy the events of b, making a new list
  5408.      a = lget();              read events from score input (to next s or e)
  5409.      lput(a);                      write the events of list a to score output
  5410.      a = lsepf(b);            separate the f statements from list b into list a
  5411.      a = lcat(a,b);           concatenate (append) the list b onto the list a
  5412.      lsort(a);                sort the list a into chronological order by p[2]
  5413.      a = lxins(b,"...");      extract notes of instruments ... (no new events)
  5414.      a = lxtimev(b,from,to);  extract notes of time-span, creating new events
  5415.  
  5416.      relev(e);                release the space of event e
  5417.      lrel(a);                      release the space of list a (but not events)
  5418.      lrelev(a);               release the events of list a, and the list space
  5419.  
  5420. Writing a Main program.
  5421.  
  5422. The general format for a main program is:
  5423.  
  5424.      #include  <csound/cscore.h>
  5425.      main()
  5426.      {
  5427.           /*  VARIABLE DECLARATIONS     */
  5428.  
  5429.           /*  PROGRAM BODY         */
  5430.      }
  5431.  
  5432. The include statement will define the event and list structures
  5433. for the program.  The following C program will read from a
  5434. standard numeric score, up to (but not including) the first s or
  5435. e statement, then write that data (unaltered) as output.
  5436.  
  5437.      #include  <csound/cscore.h>
  5438.      main()
  5439.      {
  5440.           struct evlist *a;   /* a is allowed to point to an event list */
  5441.  
  5442.           a = lget();         /* read events in, return the list pointer */
  5443.           lput(a);       /* write these events out (unchanged) */
  5444.           putstr("e");        /* write the string e to output */
  5445.      }
  5446.  
  5447. After execution of lget(), the variable a points to a list of
  5448. event addresses, each of which points to a stored event.  We have
  5449. used that same pointer to enable another list function (lput) to
  5450. access and write out all of the events that were read.  If we now
  5451. define another symbol e to be an event pointer, then the
  5452. statement
  5453.  
  5454.           e = a->e[4];
  5455.  
  5456. will set it to the contents of the 4th slot in the evlist
  5457. structure.  The contents is a pointer to an event, which is
  5458. itself comprised of an array of parameter field values.  Thus the
  5459. term e->p[5] will mean the value of parameter field 5 of the 4th
  5460. event in the evlist denoted by a.  The program below will
  5461. multiply the value of that pfield by 2 before writing it out.
  5462.  
  5463.      #include  <csound/cscore.h>
  5464.      main()
  5465.      {
  5466.           struct event  *e;        /* a pointer to an event          */
  5467.           struct evlist *a;
  5468.  
  5469.           a = lget();         /* read a score as a list of events    */
  5470.           e = a->e[4];        /* point to event 4 in event list \fIa\fR */
  5471.           e->p[5] *= 2;       /* find pfield 5, multiply its value by 2 */
  5472.           lput(a);            /* write out the list of events         */
  5473.           putstr("e");        /* add a "score end" statement          */
  5474. }
  5475.  
  5476. Now consider the following score, in which p[5] contains
  5477. frequency in cps.
  5478.  
  5479.      f 1 0 257 10 1
  5480.      f 2 0 257 7 0 300 1 212 .8
  5481.      i 1 1 3 0 440 10000
  5482.      i 1 4 3 0 256 10000
  5483.      i 1 7 3 0 880 10000
  5484.      e
  5485.  
  5486. If this score were given to the preceding main program, the
  5487. resulting output would look like this:
  5488.  
  5489.      f 1 0 257 10 1
  5490.      f 2 0 257 7 0 300 1 212 .8
  5491.      i 1 1 3 0 440 10000
  5492.      i 1 4 3 0 512 10000      ; p[5] has become 512 instead of 256.
  5493.      i 1 7 3 0 880 10000
  5494.      e
  5495.  
  5496. Note that the 4th event is in fact the second note of the score. 
  5497. So far we have not distinguished between notes and function table
  5498. setup in a numeric score.  Both can be classed as events.  Also
  5499. note that our 4th event has been stored in e[4] of the structure. 
  5500. For compatibility with Csound pfield notation, we will ignore
  5501. p[0] and e[0] of the event and list structures, storing p1 in
  5502. p[1], event 1 in e[1], etc.  The Cscore functions all adopt this
  5503. convention.
  5504.  
  5505. As an extension to the above, we could decide to use a and e to
  5506. examine each of the events in the list.  Note that e has not
  5507. preserved the numeral 4, but the contents of that slot.  To
  5508. inspect p5 of the previous listed event we need only redefine e
  5509. with the assignment
  5510.  
  5511.           e = a->e[3];
  5512.  
  5513. More generally, if we declare a new variable f to be a pointer to
  5514. a pointer to an event, the statement
  5515.  
  5516.           f = &a->e[4];
  5517.  
  5518. will set f to the address of the fourth event in the event list
  5519. a, and *f will signify the contents of the slot, namely the event
  5520. pointer itself.  The expression
  5521.  
  5522.           (*f)->p[5],
  5523.  
  5524. like e->p[5], signifies the fifth pfield of the selected event. 
  5525. However, we can advance to the next slot in the evlist by
  5526. advancing the pointer f.  In C this is denoted by f++.
  5527.  
  5528. In the following program we will use the same input score.  This
  5529. time we will separate the ftable statements from the note
  5530. statements.  We will next write the three note-events stored in
  5531. the list a, then create a second score section consisting of the
  5532. original pitch set and a transposed version of itself.  This will
  5533. bring about an octave doubling.
  5534.  
  5535. By pointing the variable f to the first note-event and
  5536. incrementing f inside a while block which iterates n times (the
  5537. number of events in the list), one statement can be made to act
  5538. upon the same pfield of each successive event.
  5539.  
  5540.      #include  <csound/cscore.h>
  5541.      main()
  5542.      {
  5543.           struct event *e,**f;          /* declarations. see pp.8-9 in the */
  5544.           struct evlist *a,*b;          /* C language programming manual */
  5545.           int n;
  5546.  
  5547.           a = lget();              /* read score into event list "a" */
  5548.           b = lsepf(a);            /* separate f statements */
  5549.           lput(b);                 /* write f statements out to score */
  5550.           lrelev(b);               /* and release the spaces used     */
  5551.           e = defev("t 0 120");    /* define event for tempo statement */
  5552.           putev(e);                /* write tempo statement to score */
  5553.           lput(a);                 /* write the notes */
  5554.           putstr("s");             /* section end */
  5555.           putev(e);                /* write tempo statement again */
  5556.           b = lcopyev(a);          /* make a copy of the notes in "a" */
  5557.           n = lcount(b);           /* and count the number copied */
  5558.           f = &a->e[1];
  5559.           while (n--)              /* iterate the following line n times: */
  5560.               (*f++)->p[5] *= .5;  /*   transpose pitch down one octave */
  5561.           a = lcat(b,a);           /* now add these notes to original pitches */
  5562.           lput(a);
  5563.           putstr("e");
  5564.      }
  5565.  
  5566. The output of this program is:
  5567.  
  5568.      f 1 0 257 10 1
  5569.      f 2 0 257 7 0 300 1 212 .8
  5570.      t 0 120
  5571.      i 1 1 3 0 440 10000
  5572.      i 1 4 3 0 256 10000
  5573.      i 1 7 3 0 880 10000
  5574.      s
  5575.      t 0 120
  5576.      i 1 1 3 0 440 10000
  5577.      i 1 4 3 0 256 10000
  5578.      i 1 7 3 0 880 10000
  5579.      i 1 1 3 0 220 10000
  5580.      i 1 4 3 0 128 10000
  5581.      i 1 7 3 0 440 10000
  5582.      e
  5583.  
  5584. Next we extend the above program by using the while statement to
  5585. look at p[5] and p[6].  In the original score p[6] denotes
  5586. amplitude.  To create a diminuendo in the added lower octave,
  5587. which is independent from the original set of notes, a variable
  5588. called dim will be used.
  5589.  
  5590.      #include <csound/cscore.h>
  5591.      main()
  5592.      {
  5593.           struct event *e,**f;
  5594.           struct evlist *a,*b;
  5595.           int n, dim;              /* declare new variable as integer */
  5596.  
  5597.           a = lget();
  5598.           b = lsepf(a);
  5599.           lput(b);
  5600.           lrelev(b);
  5601.           e = defev("t 0 120");
  5602.           putev(e);
  5603.           lput(a);
  5604.           putstr("s");
  5605.           putev(e);           /* write out another tempo statement */
  5606.           b = lcopyev(a);
  5607.           n = lcount(b);
  5608.           dim = 0;            /* initialize dim to 0 */
  5609.           f = &a->e[1];
  5610.           while (n--){
  5611.                (*f)->p[6] -= dim;  /* subtract current value of dim */
  5612.                (*f++)->p[5] *= .5; /* transpose, move f to next event */
  5613.                dim += 2000;        /* increase dim for each note */
  5614.           }
  5615.           a = lcat(b,a);
  5616.           lput(a);
  5617.           putstr("e");
  5618.      }
  5619.  
  5620. The increment of f in the above programs has depended on certain
  5621. precedence rules of C.  Although this keeps the code tight, the
  5622. practice can be dangerous for beginners.  Incrementing may
  5623. alternately be written as a separate statement to make it more
  5624. clear.
  5625.  
  5626.           while (n--){
  5627.                (*f)->p[6] -= dim;
  5628.                (*f)->p[5] *= .5;
  5629.                dim += 2000;
  5630.                f++;
  5631.           }
  5632.  
  5633. Using the same input score again, the output from this program
  5634. is:
  5635.  
  5636.      f 1 0 257 10 1
  5637.      f 2 0 257 7 0 300 1 212 .8
  5638.      t 0 120
  5639.      i 1 1 3 0 440 10000
  5640.      i 1 4 3 0 256 10000
  5641.      i 1 7 3 0 880 10000
  5642.      s
  5643.      t 0 120
  5644.      i 1 1 3 0 440 10000           ; Three original notes at
  5645.      i 1 4 3 0 256 10000           ; beats 1,4 and 7 with no dim.
  5646.      i 1 7 3 0 880 10000
  5647.      i 1 1 3 0 220 10000           ; three notes transposed down one octave
  5648.      i 1 4 3 0 128 8000            ; also at beats 1,4 and 7 with dim.
  5649.      i 1 7 3 0 440 6000
  5650.      e
  5651.  
  5652. In the following program the same three-note sequence will be
  5653. repeated at various time intervals.  The starting time of each
  5654. group is determined by the values of the array cue.  This time
  5655. the dim will occur for each group of notes rather than each note. 
  5656. Note the position of the statement which increments the variable
  5657. dim outside the inner while block.
  5658.  
  5659.      #include  <csound/cscore.h>
  5660.  
  5661.      int cue[3]={0,10,17};              /* declare array of 3 integers */
  5662.  
  5663.      main()
  5664.      {
  5665.           struct event *e, **f;
  5666.           struct evlist *a, *b;
  5667.           int n, dim, cuecount, holdn;       /* declare new variables */
  5668.  
  5669.           a = lget();
  5670.           b = lsepf(a);
  5671.           lput(b);
  5672.           lrelev(b);
  5673.           e = defev("t 0 120");
  5674.           putev(e);
  5675.           n = lcount(a);
  5676.           holdn = n;                    /* hold the value of "n" to reset below */
  5677.           cuecount = 0;                 /* initilize cuecount to "0" */
  5678.           dim = 0;
  5679.           while (cuecount <= 2) {       /* count 3 iterations of inner "while" */
  5680.                f = &a->e[1];            /* reset pointer to first event of list "a" */
  5681.                n = holdn;                /* reset value of "n" to original note count */
  5682.                while (n--) {
  5683.                (*f)->p[6] -= dim;
  5684.                (*f)->p[2] += cue[cuecount];       /* add values of cue */
  5685.                f++;
  5686.                }
  5687.                printf("; diagnostic:  cue = %d\n", cue[cuecount]);
  5688.                cuecount++;
  5689.                dim += 2000;
  5690.                lput(a);
  5691.           }
  5692.           putstr("e");
  5693.      }
  5694.  
  5695. Here the inner while block looks at the events of list a (the
  5696. notes) and the outer while block looks at each repetition of the
  5697. events of list a (the pitch group repetitions).  This program
  5698. also demonstrates a useful trouble-shooting device with the
  5699. printf function. The semi-colon is first in the character string
  5700. to produce a comment statement in the resulting score file.  In
  5701. this case the value of cue is being printed in the output to
  5702. insure that the program is taking the proper array member at the
  5703. proper time.  When output data is wrong or error messages are
  5704. encountered, the printf function can help to pinpoint the
  5705. problem.
  5706.  
  5707. Using the identical input file, the C program above will
  5708. generate:
  5709.  
  5710.      f 1 0 257 10 1
  5711.      f 2 0 257 7 0 300 1 212 .8
  5712.      t 0 120
  5713.  
  5714.      ; diagnostic:  cue = 0
  5715.      i 1 1 3 0 440 10000
  5716.      i 1 4 3 0 256 10000
  5717.      i 1 7 3 0 880 10000
  5718.  
  5719.      ; diagnostic:  cue = 10
  5720.      i 1 11 3 0 440 8000
  5721.      i 1 14 3 0 256 8000
  5722.      i 1 17 3 0 880 8000
  5723.  
  5724.      ; diagnostic:  cue = 17
  5725.      i 1 28 3 0 440 4000
  5726.      i 1 31 3 0 256 4000
  5727.      i 1 34 3 0 880 4000
  5728.      e
  5729.  
  5730. Further development of these scores will lead the composer to
  5731. techniques of score manipulation which are similar to serial
  5732. techniques of composition.  Pitch sets may be altered with regard
  5733. to any of the parameter fields.  The programing allows
  5734. transpositions, time warping, pitch retrograding and dynamic
  5735. controls, to name a few.
  5736.  
  5737. Compiling a Cscore program
  5738.  
  5739. A Cscore program example.c is compiled and linked with its
  5740. library modules by the command:
  5741.  
  5742.      $ cc  -o myprog  example.c  -lcscore
  5743.  
  5744. The resulting executable file myprog is run by typing:
  5745.  
  5746.      $ myprog                 (no input, output printed on the screen)
  5747.      $ myprog < scorin        (input score named \fIscorin\fR, output on screen)
  5748.      $ myprog < scorin  > scorout       (input as above, output into a file)
  5749.  
  5750.  
  5751. Appendix 3: An Instrument Design Tutorial
  5752. by
  5753. Richard Boulanger
  5754. Berklee College of Music
  5755.  
  5756. Csound instruments are created in an "orchestra" file, and the
  5757. list of notes to play is written in a separate "score" file. 
  5758. Both are created using a standard word processor.  When you run
  5759. Csound on a specific orchestra and score, the score is sorted and
  5760. ordered in time, the orchestra is translated and loaded, the
  5761. wavetables are computed and filled, and then the score is
  5762. performed.  The score drives the orchestra by telling the
  5763. specific instruments when and for how long to play, and what
  5764. parameters to use during the course of each note event.
  5765.  
  5766. Unlike today's commercial hardware synthesizers, which have a
  5767. limited set of oscillators, envelope generators, filters, and a
  5768. fixed number of ways in which these can be interconnected,
  5769. Csound's power is not limited.  If you want an instrument with
  5770. hundreds of oscillators, envelope generators, and filters you
  5771. just type them in.   More important is the freedom to
  5772. interconnect the modules, and to interrelate the parameters which
  5773. control them.  Like acoustic instruments, Csound instruments can
  5774. exhibit a sensitivity to the musical context, and display a level
  5775. of "musical intelligence" to which hardware synthesizers can only
  5776. aspire.
  5777.  
  5778. Because the intent of this tutorial is to familiarize the novice
  5779. with the syntax of the language, we will design several simple
  5780. instruments.  You will find many instruments of the
  5781. sophistication described above in various Csound directories, and
  5782. a study of these will reveal Csound's real power.
  5783.  
  5784. The Csound orchestra file has two main parts: 
  5785.     1.  the "header" section  -  defining the sample rate,
  5786. control rate, and number of output channels.
  5787.     2.  the "instrument" section  -  in which the instruments 
  5788. are designed.
  5789.  
  5790. The Header Section:  A Csound orchestra generates signals at two
  5791. rates - an audio sample rate and a control sample rate.  Each can
  5792. represent signals with frequencies no higher than half that rate,
  5793. but the distinction between audio signals and sub-audio control
  5794. signals is useful since it allows slower moving signals to
  5795. require less compute time.  In the header below, we have
  5796. specified a sample rate of 16kHz, a control rate of 1kHz, and
  5797. then calculated the number of samples in each control period
  5798. using the formula:  ksmps = sr / kr.  
  5799.  
  5800.                     sr   =         16000  
  5801.                     kr   =         1000
  5802.                     ksmps     =         16
  5803.                     nchnls    =         1
  5804.  
  5805. In Csound orchestras and scores, spacing is arbitrary.  It is
  5806. important to be consistent in laying out your files, and you can
  5807. use spaces to help this.  In the Tutorial Instruments shown below
  5808. you will see we have adopted one convention.  The reader can
  5809. choose his or her own.
  5810.  
  5811. The Instrument Section:  All instruments are numbered and are
  5812. referenced thus in the score.  Csound instruments are similar to
  5813. patches on a hardware synthesizer.  Each instrument consists of a
  5814. set of "unit generators," or software "modules," which are
  5815. "patched" together with  "i/o" blocks  ע i, k, or a variables. 
  5816. Unlike a hardware module, a software module has a number of
  5817. variable "arguments" which the user sets to determine its
  5818. behavior.  The four types of variables are:
  5819.  
  5820.           setup only
  5821.           i-rate variables, changed at the note rate
  5822.           k-rate variables, changed at the control signal rate
  5823.           a-rate variables, changed at the audio signal rate
  5824.  
  5825. Orchestra Statements:   Each statement occupies a single line and
  5826. has the same basic format:
  5827.      
  5828.           result    action    arguments
  5829.  
  5830. To include an oscillator in our orchestra, you might specify it
  5831. as follows:
  5832.  
  5833.           a1        oscil          10000, 440, 1
  5834.  
  5835. The three "arguments" for this oscillator set its amplitude
  5836. (10000), its frequency (440Hz), and its waveshape (1).   The
  5837. output is put in i/o block "a1."   This output symbol is
  5838. significant in prescribing the rate at which the oscillator
  5839. should generate outputעhere the audio rate.  We could have named
  5840. the result anything (e.g. "asig") as long as it began with the
  5841. letter "a".
  5842.  
  5843. Comments:  To include text in the orchestra or score which will
  5844. not be interpreted by the program, precede it with a semicolon. 
  5845. This allows you to fully comment your code.  On each line, any
  5846. text which follows a semicolon will be ignored by the orchestra
  5847. and score translators.  
  5848.  
  5849. Tutorial Instruments
  5850.  
  5851. Toot 1: Play One Note
  5852.  
  5853. For this and all instrument examples below, there exist orchestra
  5854. and score files in the Csound subdirectory tutorfiles that the
  5855. user can run to soundtest each feature introduced.  The
  5856. instrument code shown below is actually preceded by an orchestra
  5857. header section similar to that shown above.  If you are running
  5858. on a RISC computer, each example will likely run in realtime. 
  5859. During playback (realtime or otherwise) the audio rate may
  5860. automatically be modified to suit the local d-a converters.
  5861.   
  5862. The first orchestra file, called toot1.orc, contains a single
  5863. instrument which uses an oscil unit to play a 440Hz sine wave
  5864. (defined by f1 in the score) at an amplitude of 10000.  
  5865.  
  5866.      instr 1
  5867.         a1     oscil     10000, 440, 1
  5868.                     out  a1
  5869.      endin
  5870.  
  5871. Run this with its corresponding score file, toot1.sco :
  5872.  
  5873.         f1     0    4096 10   1    ; use "gen1" to compute a sine wave
  5874.         i1     0    4              ; run "instr 1" from time 0 for 4 seconds
  5875.         e                          ; indicate the "end" of the score 
  5876.  
  5877. Toot 2: "P-Fields"
  5878.  
  5879. The first instrument was not interesting because it could play
  5880. only one note at one amplitude level.  We can make things more
  5881. interesting by allowing the pitch and amplitude to be defined by
  5882. parameters in the score.  Each column in the score constitutes a
  5883. parameter field, numbered from the left.   The first three
  5884. parameter fields of the i-statement have a reserved function:
  5885.  
  5886.      p1 = instrument number
  5887.      p2 = start time
  5888.      p3 = duration
  5889.  
  5890. All other parameter fields are determined by the way the sound
  5891. designer defines his instrument.  In the instrument below, the
  5892. oscillator's amplitude argument is replaced by p4 and the
  5893. frequency argument by p5.  Now we can change these values at
  5894. i-time, i.e. with each note in the score.  The orchestra and
  5895. score files now look like:
  5896.  
  5897.           instr     2
  5898.           a1     oscil     p4, p5, 1         ; p4=amp
  5899.                  out  a1                     ; p5=freq
  5900.           endin
  5901.  
  5902.      f1   0    4096 10   1                   ; sine wave
  5903. ; instrument   start     duration    amp(p4) freq(p5)
  5904.      i2   0    1        2000  880
  5905.      i2   1.5  1        4000  440
  5906.      i2   3    1        8000  220
  5907.      i2   4.5  1      16000   110
  5908.      i2   6    1      32000   55
  5909.       e
  5910.                                     
  5911. Toot 3: Envelopes
  5912.  
  5913. Although in the second instrument we could control and vary the
  5914. overall amplitude from note to note, it would be more musical if
  5915. we could contour the loudness during the course of each note.  To
  5916. do this we'll need to employ an additional unit generator linen,
  5917. which the Csound reference manual defines as follows:
  5918.  
  5919.      kr   linen     kamp, irise, idur, idec
  5920.      ar   linen     xamp, irise, idur, idec
  5921.  
  5922. linen is a signal modifier, capable of computing its output at
  5923. either control or audio rates.  Since we plan to use it to modify
  5924. the amplitude envelope of the oscillator, we'll choose the latter
  5925. version.  Three of linen's arguments expect i-rate variables. 
  5926. The fourth expects in one instance a k-rate variable (or anything
  5927. slower), and in the other an x-variable (meaning a-rate or
  5928. anything slower).  Our linen we will get its amp from p4.  
  5929.  
  5930. The output of the linen (k1) is patched into the kamp argument of
  5931. an oscil.  This applies an envelope to the oscil.   The orchestra
  5932. and score files now appear as:
  5933.  
  5934.      instr 3
  5935.         k1     linen     p4, p6, p3, p7      ; p4=amp
  5936.         a1     oscil     k1, p5, 1      ; p5=freq
  5937.                out  a1             ; p6=attack time
  5938.      endin                         ; p7=release time
  5939.  
  5940.    f1  0  4096  10  1                        ; sine wave
  5941. ; instr   start  duration  amp(p4)   freq(p5)   attack(p6)  release(p7) 
  5942.    i3     0           1    10000        440       .05         .7
  5943.    i3     1.5         1    10000        440       .9          .1
  5944.    i3     3           1    5000         880       .02         .99
  5945.    i3     4.5         1    5000         880       .7          .01
  5946.    i3     6           2    20000        220       .5          .5
  5947. e
  5948.  
  5949. Toot 4: Chorusing
  5950.  
  5951. Next we'll animate the basic sound by mixing it with two slightly
  5952. detuned copies of itself.  We'll employ Csound's "cpspch" value
  5953. converter which will allow us to specify the pitches by octave
  5954. and pitch-class rather than by frequency, and we'll use the
  5955. "ampdb" converter to specify loudness in dB rather than linearly. 
  5956.  
  5957.  
  5958. Since we are adding the outputs of three oscillators, each with
  5959. the same amplitude envelope, we'll scale the amplitude before we
  5960. mix them.  Both "iscale" and "inote" are arbitrary names to make
  5961. the design a bit easier to read.  Each is an i-rate variable,
  5962. evaluated when the instrument is initialized.
  5963.  
  5964.           instr 4                       ; toot4.orc
  5965.             iamp = ampdb(p4)            ; convert decibels to
  5966. linear amp
  5967.             iscale = iamp * .333             ; scale the amp at
  5968. initialization
  5969.             inote = cpspch(p5)               ; convert
  5970. "octave.pitch" to cps
  5971.             k1 linen     iscale, p6, p3, p7  ; p4=amp
  5972.             a3 oscil     k1, inote*.996, 1   ; p5=freq
  5973.             a2 oscil     k1, inote*1.004, 1  ; p6=attack time
  5974.             a1 oscil     k1, inote, 1        ; p7=release time
  5975.             a1 =    a1 + a2 + a3                      
  5976.                out  a1             
  5977.           endin     
  5978.      
  5979.    f1 0 4096 10 1                                 ; sine wave
  5980. ; instr    start  duration  amp(p4)   freq(p5)  attack(p6) release(p7)         
  5981.    i4       0  1        75          8.04     .1     .7
  5982.    i4       1  1        70          8.02     .07    .6
  5983.    i4       2  1        75          8.00     .05    .5
  5984.    i4       3  1        70          8.02     .05    .4
  5985.    i4       4  1        85          8.04     .1     .5
  5986.    i4       5  1        80          8.04     .05    .5
  5987.    i4       6  2        90          8.04     .03     1
  5988. e
  5989.  
  5990. Toot 5: Vibrato
  5991.  
  5992. To add some delayed vibrato to our chorusing instrument we use
  5993. another oscillator for the vibrato and a line segment generator,
  5994. linseg, as a means of controlling the delay.  linseg is a k-rate
  5995. or a-rate signal generator which traces a series of straight line
  5996. segments between any number of specified points.  The Csound
  5997. manual describes it as:
  5998.  
  5999.      kr   linseg    ia, idur1, ib[, idur2, ic[...]]
  6000.      ar   linseg    ia, idur1, ib[, idur2, ic[...]]
  6001.  
  6002. Since we intend to use this to slowly scale the amount of signal
  6003. coming from our vibrato oscillator, we'll choose the k-rate
  6004. version.  The i-rate variables: ia, ib, ic, etc., are the values
  6005. for the points.  The i-rate variables: idur1, idur2, idur3, etc.,
  6006. set the duration, in seconds, between segments.
  6007.  
  6008.  
  6009.           instr 5                            ; toot5.orc
  6010.              irel = .01                           ; set vibrato release time
  6011.              idel1 = p3 - (p10 * p3)              ; calculate initial delay (% of dur)         isus   = p3 - (idel1- irel)      
  6012.         ; calculate remaining duration     
  6013.              iamp = ampdb(p4)
  6014.              iscale = iamp * .333            ; p4=amp
  6015.              inote = cpspch(p5)                   ; p5=freq       
  6016.  
  6017.              k3     linseg    0, idel1, p9, isus, p9, irel, 0  ; p6=attack time
  6018.              k2     oscil     k3, p8, 1                ; p7=release time    
  6019.              k1     linen     iscale, p6, p3, p7       ; p8=vib rate
  6020.              a3     oscil     k1, inote*.995+k2, 1     ; p9=vib depth   
  6021.              a2     oscil     k1, inote*1.005+k2, 1    ; p10=vib delay (0-1)
  6022.              a1     oscil     k1, inote+k2, 1                
  6023.                     out  a1+a2+a3                      
  6024.           endin     
  6025.      
  6026.         f 1  0  4096  10  1
  6027.      ; ins     strt dur  amp  frq       atk       rel       vibrt   vibdpth  vibdel     
  6028.         i5     0    3    86   10.00      .1  .7   7    6    .4
  6029.         i5     4    3    86   10.02      1   .2   6    6    .4
  6030.         i5     8    4    86   10.04      2   1    5    6    .4
  6031.      e
  6032.  
  6033. Toot 6: Gens
  6034.  
  6035. The first character in a score statement is an opcode,
  6036. determining an action request; the remaining data consists of
  6037. numeric parameter fields (p-fields) to be used by that action. 
  6038. So far we have been dealing with two different opcodes in our
  6039. score: f and i.   I-statements, or note statements, invoke the p1
  6040. instrument at time p2 and turn it off after p3 seconds; all
  6041. remaining p-fields are passed to the instrument.
  6042.  
  6043. F-statements, or lines with an opcode of f, invoke
  6044. function-drawing subroutines called GENS.  In Csound there are
  6045. currently seventeen gen routines which fill wavetables in a
  6046. variety of ways.  For example, GEN01 transfers data from a
  6047. soundfile; GEN07 allows you to construct functions from segments
  6048. of straight lines; and GEN10, which we've been using in our
  6049. scores so far, generates composite waveforms made up of a
  6050. weighted sum of simple sinusoids.   We have named the function
  6051. "f1," invoked it at time 0, defined it to contain 512 points, and
  6052. instructed GEN10 to fill that wavetable with a single sinusoid
  6053. whose amplitude is 1.  GEN10 can in fact be used to approximate a
  6054. variety of other waveforms, as illustrated by the following:
  6055.                                              
  6056.      f1   0    2048 10   1                                  ; Sine
  6057.      f2   0    2048 10   1    .5    .3   .25 .2   .167   .14  .125 .111 ; Sawtooth
  6058.      f3   0    2048 10   1    0      .3    0 .2    0       .14     0   .111      ; Square
  6059.      f4   0    2048 10   1    1      1     1 .7    .5      .3      .1       ; Pulse
  6060.  
  6061. For the opcode f, the first four p-fields are interpreted as follows:
  6062.  
  6063.      p1 - table number - In the orchestra, you reference this table by its number.
  6064.      p2 - creation time - The time at which the function is generated.
  6065.      p3 - table size - Number of points in table - must be a power of 2,  or that plus 1.
  6066.      p4 - generating subroutine - Which of the 17 GENS will you employ.   
  6067.      p5 -> p?  -  meaning determined by the particular GEN subroutine.
  6068.  
  6069. In the instrument and score below, we have added three additional
  6070. functions to the score, and modified the orchestra so that the
  6071. instrument can call them via p11.
  6072.  
  6073.           instr 6                            ; toot6.orc
  6074.              ifunc = p11                     ; select basic waveform
  6075.              irel = .01                      ; set vibrato release
  6076.              idel1 = p3 - (p10 * p3)         ; calculate initial delay
  6077.              isus   = p3 - (idel1- irel)     ; calculate remaining dur
  6078.              iamp = ampdb(p4)
  6079.              iscale = iamp * .333            ; p4=amp
  6080.              inote = cpspch(p5)              ; p5=freq       
  6081.  
  6082.              k3     linseg    0, idel1, p9, isus, p9, irel, 0   ; p6=attack time
  6083.              k2     oscil     k3, p8, 1                ; p7=release time       
  6084.              k1     linen     iscale, p6, p3, p7       ; p8=vib rate
  6085.              a3     oscil     k1, inote*.999+k2, ifunc ; p9=vib depth   
  6086.                     a2   oscil     k1, inote*1.001+k2, ifunc    ; p10=vib delay (0-1)
  6087.              a1     oscil     k1, inote+k2, ifunc
  6088.                out  a1 + a2 + a3
  6089.           endin
  6090.  
  6091.    f1 0 2048 10 1                                           ; Sine
  6092.    f2 0 2048 10 1 .5 .3 .25 .2 .167 .14 .125 .111           ; Sawtooth
  6093.    f3 0 2048 10 1 0  .3  0   .2  0  .14  0   .111           ; Square
  6094.    f4 0 2048 10 1 1 1 1 .7 .5 .3 .1                         ; Pulse
  6095. ; ins  strt   dur   amp  frq  atk  rel  vibrt   vibdpth  vibdel  waveform(f)
  6096.    i6     0    2    86   8.00 .03  .7   6    9    .8   1
  6097.    i6     3    2    86   8.02 .03  .7   6    9    .8   2
  6098.    i6     6    2    86   8.04 .03  .7   6    9    .8   3
  6099.    i6     9    3    86   8.05 .03  .7   6    9    .8   4
  6100. e
  6101.  
  6102. Toot 7: Crossfade
  6103.  
  6104. Now we will add the ability to do a linear crossfade between any
  6105. two of our four basic waveforms.  We will employ our delayed
  6106. vibrato scheme to regulate the speed of the crossfade.
  6107.  
  6108.           instr 7                            ; toot7.orc
  6109.              ifunc1 = p11                    ; initial waveform
  6110.              ifunc2 = p12                    ; crossfade waveform
  6111.              ifad1 = p3 - (p13 * p3)         ; calculate initial fade
  6112.              ifad2 = p3 - ifad1              ; calculate remaining dur
  6113.              irel = .01                      ; set vibrato release
  6114.              idel1 = p3 - (p10 * p3)         ; calculate initial delay
  6115.              isus   = p3 - (idel1- irel)     ; calculate remaining dur
  6116.              iamp = ampdb(p4)
  6117.              iscale = iamp * .166            ; p4=amp
  6118.              inote = cpspch(p5)              ; p5=freq
  6119.              k3     linseg    0, idel1, p9, isus, p9, irel, 0    ; p6=attack time
  6120.              k2     oscil     k3, p8, 1                ; p7=release time
  6121.              k1     linen     iscale, p6, p3, p7       ; p8=vib rate
  6122.              a6     oscil     k1, inote*.998+k2, ifunc2     ; p9=vib depth
  6123.              a5     oscil     k1, inote*1.002+k2, ifunc2    ; p10=vib delay (0-1)
  6124.              a4     oscil     k1, inote+k2, ifunc2          ; p11=initial wave
  6125.              a3     oscil     k1, inote*.997+k2, ifunc1     ; p12=cross wave
  6126.              a2     oscil     k1, inote*1.003+k2, ifunc1    ; p13=fade time
  6127.              a1     oscil     k1, inote+k2, ifunc1             
  6128.              kfade  linseg 1, ifad1, 0, ifad2, 1
  6129.              afunc1 = kfade * (a1+a2+a3)
  6130.              afunc2 = (1 - kfade) * (a4+a5+a6)
  6131.                out  afunc1 + afunc2
  6132.           endin
  6133.  
  6134.    f1 0 2048 10 1                                           ; Sine
  6135.    f2 0 2048 10 1 .5 .3 .25 .2 .167 .14 .125 .111           ; Sawtooth
  6136.    f3 0 2048 10 1 0  .3  0   .2  0  .14  0   .111           ; Square
  6137.    f4 0 2048 10 1 1 1 1 .7 .5 .3 .1                         ; Pulse
  6138. ; ins  strt  dur  amp  frq     atk rel vibrt vbdpt vibdel startwave   endwave   crosstime
  6139.    i7   0      5     96   8.07  .03  .1    5     6       .99        1            2          .1
  6140.    i7   6      5     96   8.09  .03  .1    5     6       .99        1            3          .1
  6141.    i7 12      8     96   8.07  .03  .1    5     6       .99        1             4          .1
  6142.  
  6143. Toot 8: Soundin
  6144.  
  6145. Now instead of continuing to enhance the same instrument, let us
  6146. design a totally different one.  We'll read a soundfile into the
  6147. orchestra, apply an amplitude envelope to it, and add some
  6148. reverb.  To do this we will employ Csound's soundin and reverb
  6149. generators.  The first is described as:
  6150.  
  6151.           a1   soundin   ifilcod[, iskiptime][, iformat]
  6152.  
  6153. soundin derives its signal from a pre-existing file.  ifilcod is
  6154. either the filename in double quotes, or an integer suffix (.n)
  6155. to the name "soundin".  Thus the file "soundin.5" could be
  6156. referenced either by the quoted name or by the integer 5.  To
  6157. read from 500ms into this file we might say: 
  6158.  
  6159.           a1   soundin   "soundin.5",  .5           
  6160.  
  6161. The Csound reverb generator is actually composed of four parallel
  6162. comb filters plus two allpass filters in series.  Although we
  6163. could design a variant of our own using these same primitives,
  6164. the preset reverb is convenient, and simulates a natural room
  6165. response via internal parameter values.  Only two arguments are
  6166. requiredעthe input (asig) and the reverb time (krvt).  
  6167.  
  6168.           ar   reverb    asig, krvt 
  6169.  
  6170. The soundfile instrument with artificial envelope and a reverb
  6171. (included directly) is as follows:
  6172.  
  6173.           instr 8                                 ; toot8.orc
  6174.              idur        =         p3
  6175.              iamp   =         p4
  6176.              iskiptime   =         p5   
  6177.              iattack     =         p6
  6178.              irelease    =         p7
  6179.              irvbtime    =         p8
  6180.              irvbgain    =         p9                             
  6181.                 
  6182.              kamp        linen          iamp, iattack, idur,
  6183. irelease                  
  6184.              asig        soundin   "soundin.aiff", iskiptime
  6185.              arampsig     =        kamp * asig               
  6186.              aeffect     reverb    asig, irvbtime
  6187.              arvbreturn       =         aeffect * irvbgain
  6188.                     out            arampsig + arvbreturn    
  6189.           endin     
  6190.  
  6191. ; ins  strt    dur       amp   skip     atk  rel     rvbtime rvbgain
  6192.    i8     0    1    .3   0    .03  .1   1.5  .2
  6193.    i8     2    1    .3   0    .1   .1   1.3  .2
  6194.    i8     3.5  2.25 .3   0    .5   .1   2.1  .2
  6195.    i8     4.5  2.25 .3   0    .01  .1   1.1  .2
  6196.    i8     5    2.25 .3   .1   .01  .1   1.1  .1
  6197. e
  6198.      
  6199. Toot 9: Global Stereo Reverb
  6200.  
  6201. In the previous example you may have noticed the soundin source
  6202. being "cut off" at ends of notes, because the reverb was inside
  6203. the instrument itself.  It is better to create a companion
  6204. instrument, a global reverb instrument, to which the source
  6205. signal can be sent.  Let's also make this stereo.
  6206.  
  6207. Variables are named cells which store numbers. In Csound, they
  6208. can be either local or global, are available continuously, and
  6209. can be updated at one of four ratesעsetup, i-rate, k-rate, or
  6210. a-rate.  
  6211.  
  6212. Local Variables (which begin with the letters p, i, k, or a) are
  6213. private to a particular instrument.  They cannot be read from, or
  6214. written to, by any other instrument.
  6215.  
  6216. Global Variables are cells which are accessible by all
  6217. instruments.  Three of the same four variable types are supported
  6218. (i,  k, and a), but these letters are preceded by the letter g to
  6219. identify them as "global."   Global variables are used for
  6220. "broadcasting" general values, for communicating between
  6221. instruments, and for sending sound from one instrument to
  6222. another.  
  6223.  
  6224. The reverb instr99 below receives input from instr9 via the
  6225. global a-rate variable garvbsig.  Since instr9 adds into this
  6226. global, several copies of instr9 can do this without losing any
  6227. data.  The addition requires garvbsig to be cleared before each
  6228. k-rate pass through any active instruments.  This is accomplished
  6229. first with an init statement in the orchestra header, giving the
  6230. reverb instrument a higher number than any other (instruments are
  6231. performed in numerical order), and then clearing garvbsig within
  6232. instr99 once its data has been placed into the reverb.
  6233.  
  6234.           sr        =    18900          ; toot9.orc
  6235.           kr        =    945
  6236.           ksmps     =    20
  6237.           nchnls    =    2              ; stereo
  6238.           garvbsig  init      0         ; make zero at orch init time
  6239.  
  6240.           instr 9
  6241.              idur        =    p3
  6242.              iamp   =    p4
  6243.              iskiptime   =    p5   
  6244.              iattack     =    p6
  6245.              irelease    =    p7
  6246.              ibalance    =    p8        ; panning: 1=left, .5=center, 0=right
  6247.              irvbgain    =    p9                                  
  6248.            
  6249.              kamp   linen          iamp, iattack, idur, irelease  
  6250.  
  6251.              
  6252.              asig        soundin   "soundin.aiff", iskiptime
  6253.              arampsig    =         kamp * asig                    
  6254.                     outs      arampsig * ibalance,  arampsig * (1 - ibalance)
  6255.              garvbsig    =         garvbsig + arampsig * irvbgain  
  6256.           endin     
  6257.      
  6258.           instr 99                 ; global reverb
  6259.              irvbtime    =    p4                                  
  6260.                 
  6261.              asig        reverb    garvbsig,  irvbtime ; put global signal into reverb
  6262.                     outs asig, asig     
  6263.              garvbsig    =    0              ; then clear it
  6264.           endin     
  6265.  
  6266. In the score we turn the global reverb on at time 0 and keep it
  6267. on until irvbtime after the last note.
  6268.  
  6269. ; ins     strt dur  rvbtime                  ; toot9.sco
  6270.   i99     0    9.85 2.6
  6271.  
  6272. ; ins     strt dur  amp  skip atk  rel  balance(0-1)   rvbsend
  6273.    i9     0    1    .5   0    .02  .1   1         .2
  6274.    i9     2    2    .5   0    .03  .1   0         .3
  6275.    i9     3.5  2.25 .5   0    .9   .1   .5        .1
  6276.    i9     4.5  2.25 .5   0    1.2  .1   0         .2
  6277.    i9     5    2.25 .5   0    .2   .1   1         .3
  6278. e
  6279.  
  6280. Toot 10: Filtered Noise
  6281.  
  6282. The following instrument uses the Csound rand unit to produce
  6283. noise, and a reson unit to filter it.  The bandwidth of reson
  6284. will be set at i-time, but its center frequency will be swept via
  6285. a line unit through a wide range of frequencies during each note. 
  6286. We add reverb as above.
  6287.  
  6288.      garvbsig  init      0
  6289.  
  6290.      instr 10                      ; toot10.orc
  6291.         iattack     =    .01
  6292.         irelease    =    .2
  6293.         iwhite      =    10000
  6294.         idur        =    p3
  6295.         iamp   =    p4
  6296.         isweepstart      =    p5
  6297.         isweepend   =    p6
  6298.         ibandwidth  =    p7
  6299.         ibalance    =    p8        ; pan: 1 = left, .5 = center, 0 = right
  6300.         irvbgain    =    p9                                       
  6301.       
  6302.         kamp   linen     iamp, iattack, idur, irelease
  6303.         ksweep line isweepstart, idur, isweepend                  
  6304.         asig        rand iwhite
  6305.         afilt       reson     asig, ksweep, ibandwidth
  6306.         arampsig    =    kamp * afilt                   
  6307.                outs      arampsig * ibalance, arampsig * (1 - ibalance)
  6308.         garvbsig    =    garvbsig  +  arampsig * irvbgain   
  6309.      endin
  6310.  
  6311.      instr 100
  6312.         irvbtime    =    p4                                       
  6313.                 
  6314.         asig        reverb  garvbsig,  irvbtime              
  6315.                outs      asig, asig               
  6316.         garvbsig    =    0
  6317.      endin
  6318.  
  6319. ; ins     strt      dur  rvbtime                       ;
  6320. toot10.sco
  6321.    i100   0    15   1.1
  6322.    i100   15   10   5
  6323.  
  6324. ; ins     strt      dur  amp    stswp  ndswp bndwth    
  6325. balance(0-1)  rvbsend
  6326.    i10    0    2    .05  5000 500   20  .5        .1
  6327.    i10    3    1    .05  1500 5000  30  .5        .1
  6328.    i10    5    2    .05  850  1100  40  .5        .1
  6329.    i10    8    2    .05  1100 8000  50  .5        .1
  6330.    i10    8    .5   .05  5000 1000  30  .5        .2
  6331.    i10    9    .5   .05  1000 8000  40       .5        .1
  6332.    i10    11   .5   .05  500  2100  50  .4        .2
  6333.    i10    12   .5   .05  2100 1220  75  .6        .1
  6334.    i10    13   .5   .05  1700 3500  100      .5        .2
  6335.    i10    15   5    .01  8000 800   60  .5        .15
  6336. e
  6337.  
  6338. Toot 11: Carry, Tempo & Sort
  6339.  
  6340. We now use a plucked string instrument to explore some of
  6341. Csound's score preprocessing capabilities.  Since the focus here
  6342. is on the score, the instrument is presented without explanation. 
  6343.  
  6344.  
  6345.      instr 11                                                  
  6346.           asig1     pluck     ampdb(p4)/2, p5, p5, 0, 1           
  6347.         
  6348.           asig2     pluck     ampdb(p4)/2, p5 * 1.003,  p5 * 1.003, 0, 1
  6349.                out  asig1+asig2
  6350.      endin     
  6351.  
  6352. The score can be divided into time-ordered sections by the S
  6353. statement.  Prior to performance, each section is  processed by
  6354. three routines: Carry, Tempo, and Sort.  The score toot11.sco has
  6355. multiple sections containing each of the examples below, in both
  6356. of the forms listed.
  6357.  
  6358. The Carry feature allows a dot ("." ) in a p-field to indicate
  6359. that the value is the same as above, provided the instrument is
  6360. the same.  Thus the following two examples are identical:
  6361.  
  6362. ;  ins    start     dur       amp       freq      |         ; ins  start     dur       amp  freq
  6363.    i11    0    1    90        200       |            i11    0        1     90   200
  6364.    i11    1    .    .         300       |            i11    1        1     90   300
  6365.    i11    2    .    .         400       |            i11    2        1     90   400
  6366.  
  6367. A special form of the carry feature applies to p2 only.  A "+" in
  6368. p2 will be given the value of p2+p3 from the previous i
  6369. statement.  The "+" can also be carried with a dot: 
  6370.  
  6371.  ;  ins   start     dur  amp  freq      |         ;  ins    start     dur       amp  freq
  6372.     i11   0    1         90   200       |            i11    0    1   90   200
  6373.     i     .    +    .    .    300       |            i11    1    1   90   300
  6374.     i     .    .    .    .    500       |            i11    2    1   90   500
  6375.  
  6376. The carrying dot may be omitted when there are no more explicit
  6377. pfields on that line:
  6378.  
  6379. ;  ins    start dur  amp  freq     |         ;  ins    start     dur       amp  freq 
  6380.    i11    0    1    90   200       |            i11    0    1    90   200
  6381.    i11    +    2                   |            i11    1    2    90   200
  6382.    i11                             |            i11    3    2    90   200
  6383.  
  6384. A variant of the carry feature is Ramping, which substitutes a
  6385. sequence of linearly interpolated values for a ramp symbol ( < )
  6386. spanning any two values of a pfield.  Ramps work only on
  6387. consecutive calls to the same instrument, and they cannot be
  6388. applied to the first three p-fields.
  6389.  
  6390. ; ins      start    dur  amp  freq      |         ; ins     start     dur  amp  freq
  6391.   i11     0    1    90   200       |           i11     0    1   90   200
  6392.   i .     +    .    <    <         |           i11     1    1   85   300
  6393.   i .     .    .    <    400       |           i11     2    1   80   400
  6394.   i .     .    .    <    <         |           i11     3    1   75   300
  6395.   i .     .    4    70   200       |           i11     4    4   70   200
  6396.  
  6397. Tempo.  The unit of time in a Csound score is the beatעnormally
  6398. one beat per second.  This can be modified by a Tempo Statement,
  6399. which enables the score to be arbitrarily time-warped. Beats are
  6400. converted to their equivalent in seconds during score
  6401. pre-processing of each Section.  In the absence of a Tempo
  6402. statement in any Section, the following tempo statement is
  6403. inserted:
  6404.  
  6405.           t   0   60
  6406.  
  6407. It means that at beat 0 the tempo of the Csound beat is 60 (1
  6408. beat per second).  To hear the Section at twice the speed, we
  6409. have two options:  1) cut all p2 and p3 in half and adjust the
  6410. start times, or 2) insert the statement  t  0  120  within the
  6411. Section.  
  6412.  
  6413. The Tempo statement can also be used to move between different
  6414. tempi during the score, thus enabling ritardandi and accelerandi. 
  6415. Changes are linear by beat size (see the Csound manual).  The
  6416. following statement will cause the score to begin at tempo 120,
  6417. slow to tempo 80 by beat 4, then accelerate to 220 by beat 7:
  6418.  
  6419.           t    0   120   4   80    7   220
  6420.  
  6421. The following will produce identical soundfiles:
  6422.                                          t  0  120       ; Double-time via Tempo
  6423. ; ins     start     dur  amp  freq      |         ; ins     start     dur  amp  freq
  6424.   i11     0    .5   90   200       |           i11     0    1   90   200
  6425.   i .     +    .    <    <         |           i .     +    .   <    <
  6426.   i .     .    .    <    400       |           i .     .    .   <    400
  6427.   i .     .    .    <    <         |           i .     .    .   <    <
  6428.   i .     .    2    70   200       |           i .     .    4   70   200
  6429.  
  6430. The following includes an accelerando and ritard.  It should be
  6431. noted, however, that the ramping feature is applied after
  6432. time-warping, and is thus proportional to elapsed chronological
  6433. time.  While this is perfect for amplitude ramps, frequency ramps
  6434. will not result in harmonically related pitches during tempo
  6435. changes.  The frequencies needed here are thus made explicit.
  6436.  
  6437.           t     0   60   4    400  8    60   ; Time-warping via
  6438. Tempo
  6439.      ;    ins  start     dur  amp  freq
  6440.           i11  0    1    70   200
  6441.           i .  +    .    <    500
  6442.           i .  .    .    90   800
  6443.           i .  .    .    <    500
  6444.           i .  .    .    70   200
  6445.           i .  .    .    90   1000
  6446.           i .  .    .    <    600
  6447.           i .  .    .    70   200
  6448.           i .  .    8    90   100
  6449.  
  6450. Three additional score features are extremely useful in Csound.  
  6451. The s statement was used above to divide a score into Sections
  6452. for individual pre-processing.  Since each s statement
  6453. establishes a new relative time of 0, and all actions within a
  6454. section are relative to that, it is convenient to develop the
  6455. score one section at a time, then link the sections into a whole
  6456. later.
  6457.  
  6458. Suppose we wish to combine the six above examples (call them
  6459. toot11a - toot11f) into one score.  One way is to start with
  6460. toot11a.sco, calculate its total duration and add that value to
  6461. every starting time of toot11b.sco, then add the composite
  6462. duration to the start times of toot11c.sco, etc.  Alternatively,
  6463. we could insert an s statement between each of the sections and
  6464. run the entire score.  The file toot11.sco, which contains a
  6465. sequence of all of the above score examples, did just that.
  6466.  
  6467. The f0 statement, which creates an "action time" with no
  6468. associated action, is useful in extending the duration of a
  6469. section.   Two seconds of silence are added to the first two
  6470. sections below.
  6471.  
  6472. ;    ins  start     dur  amp  freq           ; toot11g.sco
  6473.      i11  0    2    90   100
  6474.      f 0  4                             ; The f0 Statement
  6475.      s                                  ; The Section Statement
  6476.      i11  0    1    90   800 
  6477.      i .  +    .    .    400
  6478.      i .  .    .    .    100
  6479.      f 0  5
  6480.      s
  6481.      i11  0         4    90   50
  6482.      e
  6483.  
  6484. Sort.  During preprocessing of a score section, all action-time
  6485. statements are sorted into chronological order by p2 value.  This
  6486. means that notes can be entered in any order, that you can merge
  6487. files, or work on instruments as temporarily separate sections,
  6488. then have them sorted automatically when you run Csound on the
  6489. file.  
  6490.  
  6491. The file below contains excerpts from this section of the
  6492. rehearsal chapter and from instr6 of the tutorial, and combines
  6493. them as follows: 
  6494.  
  6495. ;    ins  start     dur  amp  freq           ; toot11h.sco
  6496.           i11  0    1    70   100            ; Score Sorting
  6497.           i .  +    .    <    <
  6498.           i .  .    .    <    <
  6499.           i .  .    .    90   800
  6500.           i .  .    .    <    <
  6501.           i .  .    .    <    <
  6502.           i .  .    .    70   100
  6503.           i .  .    .    90   1000
  6504.           i .  .    .    <    <
  6505.           i .  .    .    <    <
  6506.           i .  .    .    <    <
  6507.           i .  .    .    70   <
  6508.           i .  .    8    90   50
  6509.  
  6510.    f1 0 2048 10 1                            ; Sine
  6511.    f2 0 2048 10 1 .5 .3 .25 .2 .167 .14 .125 .111      ; Sawtooth
  6512.    f3 0 2048 10 1 0  .3  0   .2  0 .14  0   .111       ; Square
  6513.    f4 0 2048 10 1 1 1 1 .7 .5 .3 .1                    ; Pulse
  6514.  
  6515. ; ins     strt dur  amp  frq  atk  rel      vibrt   vibdpth  vibdel    waveform
  6516.    i6     0    2    86   9.00 .03  .1   6    5    .4   1
  6517.    i6     2    2    86   9.02 .03  .1   6    5    .4   2
  6518.    i6     4    2    86   9.04 .03  .1   6    5    .4   3
  6519.    i6     6    4    86   9.05 .05  .1   6    5    .4   4
  6520.  
  6521. Toot 12: Tables & Labels
  6522.  
  6523. This is by far our most complex instrument.  In it we have
  6524. designed the ability to store pitches in a table and then index
  6525. them in three different ways:  1) directly, 2) via an lfo,  and
  6526. 3) randomly.  As a means of switching between these three
  6527. methods, we will use Csound's program control statements and
  6528. logical and conditional operations.  
  6529.  
  6530.           instr 12
  6531.              iseed     =      p8
  6532.              iamp     =  ampdb(p4)
  6533.              kdirect  =  p5
  6534.              imeth    =  p6
  6535.              ilforate  =      p7                 ; lfo and random index rate
  6536.              itab       =     2
  6537.              itablesize =     8
  6538.  
  6539.                     if (imeth == 1)   igoto direct
  6540.                     if (imeth == 2)   kgoto lfo
  6541.                     if (imeth == 3)   kgoto random 
  6542.  
  6543.      direct:     kpitch    table      kdirect, itab         ; index "f2" via p5
  6544.                  kgoto    contin 
  6545.           
  6546.      lfo:   kindex    phasor  ilforate
  6547.             kpitch     table     kindex  *  itablesize, itab
  6548.             kgoto      contin
  6549.  
  6550.      random: kindex    randh   int(7), ilforate, iseed
  6551.             kpitch     table     abs(kindex), itab
  6552.  
  6553.      contin:   kamp      linseg   0, p3 * .1, iamp, p3 * .9, 0  ; amp envelope
  6554.             asig         oscil     kamp, cpspch(kpitch), 1    ; audio osc   
  6555.                     out       asig                   
  6556.           endin
  6557.  
  6558.   f1 0 2048 10 1                             ; Sine
  6559.   f2 0 8 -2  8.00 8.02 8.04 8.05 8.07 8.09 8.11 9.00   ; cpspch C major scale
  6560.  
  6561. ; method 1 - direct index of table values
  6562. ; ins  start   dur  amp  index  method  lforate   rndseed
  6563.   i12     0    .5   86   7    1    0    0
  6564.   i12     .5   .5   86   6    1    0
  6565.   i12     1    .5   86   5    1    0
  6566.   i12     1.5  .5   86   4    1    0
  6567.   i12     2    .5   86   3    1    0
  6568.   i12     2.5  .5   86   2    1    0
  6569.   i12     3    .5   86   1    1    0
  6570.   i12     3.5  .5   86   0    1    0
  6571.   i12     4    .5   86   0    1    0
  6572.   i12     4.5  .5   86   2    1    0
  6573.   i12     5    .5   86   4    1    0
  6574.   i12     5.5  2.5  86   7    1    0
  6575. s  
  6576.  
  6577. ; method 2 - lfo index of table values
  6578. ; ins     start     dur  amp  index   method lforate   rndseed
  6579.   i12     0    2    86   0    2    1    0
  6580.   i12     3    2    86   0    2    2
  6581.   i12     6    2    86   0    2    4
  6582.   i12     9    2    86   0    2    8
  6583.   i12     12   2    86   0    2    16
  6584. s
  6585.  
  6586. ; method 3 - random index of table values
  6587. ; ins     start     dur  amp  index  method  rndrate  rndseed
  6588.   i12     0    2    86   0    3    2    .1
  6589.   i12     3    2    86   0    3    3    .2
  6590.   i12     6    2    86   0    3    4    .3
  6591.   i12     9    2    86   0    3    7    .4
  6592.   i12     12   2    86   0    3    11   .5
  6593.   i12     15   2    86   0    3    18   .6
  6594.   i12     18   2    86   0    3    29   .7
  6595.   i12     21   2    86   0    3    47   .8
  6596.   i12     24   2    86   0    3    76   .9
  6597.   i12     27   2    86   0    3    123  .9
  6598.   i12     30   5    86   0    3    199  .1
  6599.  
  6600. Toot 13: Spectral Fusion
  6601.  
  6602. For our final instrument, we will employ three unique synthesis
  6603. methodsעPhysical Modeling, Formant-Wave Synthesis, and 
  6604. Non-linear Distortion.  Three of Csound's most powerful unit
  6605. generatorsעpluck,  fof, and foscil, make this complex task a
  6606. fairly simple one.  The Reference Manual describes these as
  6607. follows:
  6608.  
  6609.      a1    pluck   kamp, kcps, icps, ifn, imeth [, iparm1, iparm2]
  6610.  
  6611. pluck simulates the sound of naturally decaying plucked strings
  6612. by filling a cyclic decay buffer with noise and then smoothing it
  6613. over time according to one of several methods.  The unit is based
  6614. on the  Karplus-Strong algorithm.
  6615.  
  6616.      a2    fof    xamp, xfund, xform, koct, kband, kris, kdur kdec,
  6617.                iolaps, ifna, ifnb, itotdur[, iphs][, ifmode]
  6618.  
  6619. fof simulates the sound of the male voice by producing a set of
  6620. harmonically related partials (a formant region) whose spectral
  6621. envelope can be controlled over time.  It is a special form of
  6622. granular synthesis, based on the CHANT program from IRCAM by
  6623. Xavier Rodet et al.
  6624.  
  6625.      a1    foscil   xamp, kcps, kcar, kmod, kndx, ifn [, iphs]
  6626.  
  6627. foscil is a composite unit which banks two oscillators in a
  6628. simple FM configuration, wherein the audio-rate output of one
  6629. (the "modulator") is used to modulate the frequency input of
  6630. another (the "carrier.") 
  6631.  
  6632. The plan for our instrument is to have the plucked string attack
  6633. dissolve into an FM sustain which transforms into a vocal
  6634. release.  The orchestra and score are as follows:
  6635.  
  6636.      instr 13                 ; toot13.orc
  6637.         iamp   = ampdb(p4) / 2     ; amplitude, scaled for two sources
  6638.         ipluckamp   = p6           ; % of total amp, 1=dB amp as in p4
  6639.         ipluckdur   = p7*p3        ; % of total dur, 1=entire dur of note
  6640.         ipluckoff   = p3 - ipluckdur
  6641.         ifmamp      =  p8               ; % of total amp, 1=dB amp as in p4
  6642.         ifmrise     = p9*p3        ; % of total dur, 1=entire dur of note
  6643.         ifmdec      = p10*p3       ; % of total duration
  6644.         ifmoff      = p3 - (ifmrise + ifmdec)
  6645.         index  = p11
  6646.         ivibdepth   = p12
  6647.         ivibrate    = p13
  6648.         iformantamp = p14               ; % of total amp, 1=dB amp as in p4
  6649.         iformantrise     = p15*p3       ; % of total dur, 1=entire dur of note
  6650.         iformantdec = p3 - iformantrise
  6651.  
  6652.         kpluck linseg    ipluckamp, ipluckdur, 0, ipluckoff, 0
  6653.         apluck1     pluck     iamp, p5, p5, 0, 1
  6654.         apluck2     pluck     iamp, p5*1.003, p5*1.003, 0, 1
  6655.         apluck =    kpluck * (apluck1+apluck2)
  6656.  
  6657.         kfm         linseg    0, ifmrise, ifmamp, ifmdec, 0, ifmoff, 0
  6658.         kndx   =    kfm * index
  6659.         afm1   foscil    iamp, p5, 1, 2, kndx, 1
  6660.         afm2   foscil    iamp, p5*1.003, 1.003, 2.003, kndx, 1
  6661.         afm         =    kfm * (afm1+afm2)
  6662.  
  6663.         kfrmnt linseg    0, iformantrise, iformantamp, iformantdec, 0
  6664.         kvib        oscil     ivibdepth,ivibrate,1
  6665.         afrmnt1     fof    iamp, p5+kvib, 650, 0, 40, .003, .017, .007, 4, 1, 2, p3
  6666.         afrmnt2     fof    iamp, (p5*1.001)+kvib*.009, 650, 0, 40, .003,.017,.007, 10,1,2,p3
  6667.         aformnt     =    kfrmnt * (afrmnt1+afrmnt2)
  6668.  
  6669.                out  apluck + afm + aformnt
  6670.      endin
  6671.  
  6672. f1  0  8192  10  1            ; sine wave
  6673. f2  0  2048   19  .5  1  270  1         ; sigmoid rise
  6674.  
  6675. ;ins      st   dr   mp   frq  plkmp     plkdr     fmp  fmris     fmdec     indx vbdp vbrt   frmp fris
  6676.  i13 0    5    80   200  .8   .3   .7   .2   .35  8    1    5   3     .5
  6677.  i13 +    8    80   100  .    .4   .7   .35  .35  7    1    6   3     .7
  6678.  i13 .   13    80   50   .    .3   .7   .2   .4   6    1    4   3     .6
  6679.  
  6680. When Things Sound Wrong
  6681.  
  6682. When you design your own Csound instruments you may occasionally
  6683. be surprised by the results.  There will be times when you've
  6684. computed a file for hours and your playback is just silence,
  6685. while at other times you may get error messages which prevent the
  6686. score from running, or you may hang the computer and nothing
  6687. happens at all.
  6688.  
  6689. In general, Csound has a comprehensive error-checking facility
  6690. that reports to your console at various stages of your run:  at
  6691. score sorting, orchestra translation, initializing each call of
  6692. every instrument, and during performance.  However, if your error
  6693. was syntactically permissable, or it generated only a warning
  6694. message, Csound could faithfully give you results you don't
  6695. expect. Here is a list of the things you might check in your
  6696. score and orchestra files:
  6697.  
  6698.           1.  You typed the letter l instead of the number 1
  6699.  
  6700.           2.  You forgot to precede your comment with a semi-colon
  6701.  
  6702.           3.  You forgot an opcode or a required parameter
  6703.  
  6704.           4.  Your amplitudes are not loud enough or they are too loud
  6705.  
  6706.           5.  Your frequencies are not in the audio range - 20Hz to 20kHz
  6707.  
  6708.           6.  You placed the value of one parameter in the p-field of another
  6709.  
  6710.           7.  You left out some crucial information like a function definition
  6711.  
  6712.           8.  You didn't meet the Gen specifications
  6713.  
  6714. Suggestions for Further Study
  6715.  
  6716. Csound is such a powerful tool that we have touched on only a few
  6717. of its many features and uses.  You are encouraged to take apart
  6718. the instruments in this chapter, rebuild them, modify them, and 
  6719. integrate the features of one into the design of another.  To
  6720. understand their capabilities you should compose short etudes
  6721. with each.  You may be surprised to find yourself merging these
  6722. little studies into the fabric of your first Csound compositions. 
  6723.  
  6724.  
  6725. The directory 'morefiles' contains examples of the classical
  6726. designs of Risset and Chowning.  Detailed discussions of these
  6727. instruments can be found in Charles Dodge's and Thomas Jerse's
  6728. Computer Music textbook.  This text is the key to getting the
  6729. most out of these instrumental models and their innovative
  6730. approaches to signal processing.  Also recommended are the
  6731. designs of Russell Pinkston.  They demonstrate techniques for
  6732. legato phrasing, portamento, random vibrato, and random sequence
  6733. generation.  His instrument representing Dx7 OpCode¬
  6734. Editor/Librarian patches is a model for bringing many wonderful
  6735. sounds into your orchestra.
  6736.  
  6737. Nothing will increase your understanding more than actually
  6738. Making Music with Csound.   The best way to discover the full
  6739. capability of these tools is to create your own music with them. 
  6740. As you negotiate the new and uncharted terrain you will make many
  6741. discoveries.  It is my hope that through Csound you discover as
  6742. much about music as I have, and that this experience brings you
  6743. great personal satisfaction and joy.
  6744.  
  6745. Richard Boulanger   -    March 1991   -  Boston, Massachusetts  
  6746. -  USA
  6747.  
  6748. Appendix 4: An FOF Synthesis Tutorial
  6749. by
  6750. J.M.Clarke
  6751. University of Huddersfield
  6752.  
  6753. The fof synthesis generator in Csound has more parameter fields
  6754. than other modules.  To help the user become familiar with these
  6755. parameters this tutorial will take a simple orchestra file using
  6756. just one fof unit-generator and demonstrate the effect of each
  6757. parameter in turn.  To produce a good vocal imitation, or a sound
  6758. of similar sophistication, an orchestra containing five or more
  6759. fof generators is required and other refinements (use of random
  6760. variation of pitch etc.) must be made.  The sounds produced in
  6761. these initial explorations will be much simpler and consequently
  6762. less interesting but they will help to show clearly the basic
  6763. elements of fof synthesis.  This tutorial assumes a basic working
  6764. knowledge of Csound itself.  The specification of the fof
  6765. unit-generator (as found in the main Csound manual) is:
  6766.  
  6767. ar  fof  xamp  xfund  xform  koct  kband  kris  kdur  kdec 
  6768. iolaps  ifna  ifnb  itotdur [iphs] [ifmode]
  6769.  
  6770. where           xamp, xfund, xform      can receive any rate (constant, control or audio)
  6771.            koct, kband, kdris, kdur, kdec    can receive only constants or control rates
  6772.            iolaps, ifna, ifnb, itotdur       must be given a fixed value at initialization
  6773.            [iphs][ifmode]               are optional, defaulting to 0.
  6774.  
  6775. The following orchestra contains a simple instrument we will use
  6776. for exploring each parameter in turn.  On the faster machines
  6777. (DECstation, SparcStation, SGI Indigo) it will run in real time.
  6778.  
  6779.      sr = 22050
  6780.      kr = 441
  6781.      ksmps = 50
  6782.  
  6783.      instr     1
  6784. a1   fof  15000, 200, 650, 0, 40, .003, .02, .007, 5, 1, 2, p3
  6785.      out  a1
  6786.      endin
  6787.  
  6788. It should be run with the following score:
  6789.  
  6790. f1  0  4096  10  1
  6791. f2  0  1024  19  .5  .5  270  .5
  6792. i1  0  3
  6793. e
  6794.  
  6795. The result is very basic.  This is not surprising since we have
  6796. created only one formant region (a vocal imitation would need at
  6797. least five) and have no vibrato or random variation of the
  6798. parameters.   By varying one parameter at a time we will help the
  6799. reader learn how the unit-generator works.   Each of the
  6800. following "variations" starts from the model.  Parameters not
  6801. specified remain as given. 
  6802.  
  6803. xamp = amplitude
  6804.  
  6805. The first input parameter controls the amplitude of the
  6806. generator.  At present our model uses a constant amplitude, this
  6807. can be changed so that the amplitude varies according to a line
  6808. function:
  6809.  
  6810. a2   linseg    0,  p3*.3,  20000,  p3*.4,  15000,  p3*.3,  0
  6811. a1   fof  a2, ......(as before)...
  6812.  
  6813. The amplitude of a fof generator needs care.  xamp does not
  6814. necessarily indicate the maximum output, which can also depend on
  6815. the rise pattern, bandwidth, and the presence of any  "overlaps". 
  6816.  
  6817.  
  6818. xfund = fundamental frequency
  6819.  
  6820. This parameter controls the pitch of the fundamental of the unit
  6821. generator.  Starting again from the original model this example
  6822. demonstrates an exaggerated vibrato:
  6823.  
  6824. a2   oscil     20,  5,  1
  6825. a1   fof  15000,  200+a2,  etc........
  6826.  
  6827. fof synthesis produces a  rapid succession of (normally)
  6828. overlapping excitations or granules.  The fundamental is in fact
  6829. the speed at which new excitations are formed and if the
  6830. fundamental is very low these excitations are heard as separate
  6831. granules.  In this case the fundamental is not so much a pitch as
  6832. a pulse speed.  The possibility of moving between pitch and
  6833. pulse, between timbre and granular texture is one of the most
  6834. interesting aspects of fof.  For a simple demonstration try the
  6835. following variation.  It will be especially clear if the score
  6836. note is lengthened to about 10 seconds.
  6837.  
  6838. a2   expseg  5,  p3*.8,  200,  p3*.2,  150
  6839. a1   fof   15000,  a2  etc........
  6840.  
  6841. koct = octaviation coefficient
  6842.  
  6843. Skipping a parameter, we come to an unusual means of controlling
  6844. the fundamental: octaviation.  This parameter is normally set to
  6845. 0.  For each unit increase in koct the fundamental pitch will
  6846. drop by one octave.  The change of pitch is not by the normal
  6847. means of glissando, but by gradually fading out alternate
  6848. excitations (leaving half the original number).  Try the
  6849. following (again with the longer note duration):
  6850.  
  6851. k1   linseg    0,  p3*.1,  0,  p3*.8,  6,  p3*.1,  6
  6852. a1   fof  15000,  200,  650,  k1  etc.........
  6853.  
  6854. This produces a drop of six octaves;  if the note is sufficiently
  6855. long you should be able to hear the fading out of alternate
  6856. excitations towards the end.
  6857.  
  6858. xform = formant frequency;  ifmode = formant mode (0 = striated,
  6859. non-0 = smooth)
  6860.  
  6861. The spectral output of a fof unit-generator resembles that of an
  6862. impulse generator filtered by a band pass filter.  It is a set of
  6863. partials above a fundamental xfund with a spectral peak at the
  6864. formant frequency xform.  Motion of the formant can be
  6865. implemented in two ways.  If ifmode = 0,
  6866. data sent to xform has effect only at the start of a new
  6867. excitation.  That is, each excitation gets the current value of
  6868. this parameter at the time of creation and holds it until the
  6869. excitation ends.  Successive overlapping excitations can have
  6870. different formant frequencies, creating a richly varied sound. 
  6871. This is the mode of the original CHANT program.  If ifmode is
  6872. non-zero, the frequency of each excitation varies continuously
  6873. with xform.  This allows glissandi of the formant frequency.  To
  6874. demonstrate these differences we take a very low fundamental so
  6875. that the granules can be heard separately and the formant
  6876. frequency is audible not as the center frequency of a "band" but
  6877. as a pitch in its own right.  Compare the following in which only
  6878. ifmode is changed:
  6879.  
  6880. a2   line 400,  p3,  800
  6881. a1   fof  15000,  5,  a2,  0,  1,  .003,  .5,  .1,  3,  1,  2, 
  6882. p3,  0,  0
  6883.  
  6884. a2   line 400,  p3,  800
  6885. a1   fof  15000,  5,  a2,  0,  1,  .003,  .5,  .1,  3,  1,  2, 
  6886. p3,  0,  1
  6887.  
  6888. In the first case the formant frequency moves by step at the
  6889. start of each excitation, whereas in the second it changes
  6890. smoothly.  A more subtle difference is perceived with higher
  6891. fundamental frequencies.  (Note that the later fof parameters
  6892. were changed in this example to lengthen the excitations so that
  6893. their pitch could be heard easily.)
  6894.  
  6895. xform also permits frequency modulation of the formant frequency. 
  6896. Applying FM to an already complex sound can lead to strange
  6897. results, but here is a simple example:
  6898.  
  6899. acarr     line 400,  p3,  800
  6900. index     =    2.0
  6901. imodfr  = 400
  6902. idev =    index * imodfr
  6903. amodsig oscil  idev, imodfr, 1
  6904. a1   fof  15000,  5,  acarr+amodsig,  0,  1,  .003,  .5,  .1,  3, 
  6905. 1,  2,  p3,  0,  1 
  6906.  
  6907. kband = formant bandwidth
  6908. kris, kdur, kdec = risetime, duration and decaytime (in seconds)
  6909. of the excitation envelope
  6910.  
  6911. These parameters control the shape and length of the fof
  6912. granules.  They are shaped in three segments:  a rise, a middle
  6913. decay, and a terminating decay.  For very low fundamentals these
  6914. are perceived as an amplitude envelope, but with higher
  6915. fundamentals (above 30 Hz) the granules merge together and these
  6916. parameters effect the timbre of the sound.  Note that these four
  6917. parameters influence a new granule only at the time of its
  6918. initialization and are fixed for its duration;  later changes
  6919. will affect only subsequent granules.  We begin our examination
  6920. with low frequencies.
  6921.  
  6922. k1   line .003,  p3,  .1                          ; kris
  6923. a1   fof  15000,  2,  300,  0,  0,  k1,  .5,  .1,  2,  1,  2,  p3
  6924.  
  6925. Run this with a note length of 10 seconds.  Notice how the attack
  6926. of the envelope of the granules lengthens.  The shape of this
  6927. attack is determined by the forward shape of ifnb (here a
  6928. sigmoid).
  6929.  
  6930. Now try changing kband:
  6931.  
  6932. k1   linseg    0,  p3,  10                             ; kband
  6933. a1   fof  15000,  2,  300,  0,  k1,  .003,  .5,  .1,  2,  1,  2, 
  6934. p3
  6935.  
  6936. Following its rise, an excitation has a built-in exponential
  6937. decay and kband determines its rate.  The bigger kband the
  6938. steeper the decay;  zero means no decay.  In the above example
  6939. the successive granules had increasingly fast decays.  
  6940.  
  6941. k1   linseg    .3,  p3,  .003
  6942. a1   fof  15000,  2,  300,  0,  0,  .003,  .4,  k1,  2,  1,  2, p3
  6943.  
  6944. This demonstrates the operation of kdec.  Because an exponential
  6945. decay never reaches zero it must be terminated gracefully.  kdur
  6946. is the overall duration (in seconds from the start of the
  6947. excitation), and kdec is the length of the terminating decay.  In
  6948. the above example the terminating decay starts very early in the
  6949. first granules and then becomes progressively later.  Note that
  6950. kband is set to zero so that only the terminating decay is
  6951. evident.
  6952.  
  6953. In the next example the start time of the termination remains
  6954. constant, but its length gets shorter:
  6955.  
  6956. k1   expon     .3,  p3,  .003
  6957. a1   fof  15000,  2,  300,  0,  0,  .003,  .01 + k1,  k1,  2,  1, 2,  p3
  6958.  
  6959. It may be surprising to find that for higher fundamentals the
  6960. local envelope determines the spectral shape of the sound. 
  6961. Electronic and computer music has often shown how features of
  6962. music we normally consider independent (such as pitch, timbre,
  6963. rhythm) are in fact different aspects of the same thing.  In
  6964. general, the longer the local envelope segment the narrower the
  6965. band of partials around that frequency.  kband determines the
  6966. bandwidth of the formant region at -6dB, and kris  controls the
  6967. skirtwidth at -40dB.  Increasing kband increases the local
  6968. envelope's exponential decay rate, thus shortening it and
  6969. increasing the -6dbB spectral region.  Increasing kris  (the
  6970. envelope attack time) inversely makes the -40dB spectral region
  6971. smaller.
  6972.  
  6973. The next example changes first the bandwidth then the skirtwidth. 
  6974. You should be able to hear the difference.
  6975.  
  6976. k1   linseg    100,  p3/4,  0,  p3/4,  100,  p3/2,  100              ; kband
  6977. k2   linseg    .003,  p3/2,  .003,  p3/4,  .01,  p3/4,  .003         ; kris
  6978. a1   fof  15000,  100,  440,  0,  k1,  k2,  .02,  .007,  3,  1, 2,  p3 
  6979.  
  6980. [In the first half of the note kris  remains constant while kband
  6981. broadens then narrows again.  In the second half, kband is fixed
  6982. while kris lengthens (narrowing the spectrum) then returns again.]
  6983.  
  6984. Note that kdur and kdec don't really shape the spectrum, they
  6985. simply tidy up the decay so as to prevent unwanted
  6986. discontinuities which would distort the sound.  For vocal
  6987. imitations these parameters are typically set at .017 and .007
  6988. and left unchanged.  With high ("soprano") fundamentals it is
  6989. possible to shorten these values and save computation time
  6990. (reduce overlaps).
  6991.  
  6992. iolaps  = number of overlap spaces
  6993.  
  6994. Granules are created at the rate of the fundamental frequency,
  6995. and new granules are often created before earlier ones have
  6996. finished, resulting in overlaps.  The number of overlaps at any
  6997. one time is given by xfund * kdur.  For a typical bass note the
  6998. calculation might be 200 * .018 = 3.6, and for a soprano note 660
  6999. * .015 = 9.9.  fof needs at least this number (rounded up) of
  7000. spaces in which to operate.  The number can be over-estimated at
  7001. no computation cost, and at only a small space cost.   If there
  7002. are insufficient overlap spaces during operation, the note will
  7003. terminate.
  7004.  
  7005. ifna, ifnb  = stored function tables
  7006.  
  7007. Identification numbers of two function tables (see the fof entry
  7008. in the manual proper).
  7009.  
  7010. itotdur  = total duration within which all granules in a note
  7011. must be completed
  7012.  
  7013. So that incomplete granules are not cut off at the end of a note
  7014. fof will not create new granules if they will not be completed by
  7015. the time specified.  Normally given the value "p3" (the note
  7016. length), this parameter can be changed for special effect;  fof
  7017. will output zero after time itotdur.
  7018.  
  7019. iphs  = initial phase (optional, defaulting to 0).
  7020.  
  7021. Specifies the initial phase of the fundamental.  Normally zero,
  7022. but giving different fof generators different initial phases can
  7023. be helpful in avoiding "zeros" in the spectrum.
  7024.  
  7025.  
  7026.  
  7027. Appendix 5: Csound for the Macintosh
  7028. by
  7029. Bill Gardner
  7030. MIT Media Lab
  7031. Introduction
  7032.  
  7033. This document describes the Macintosh verson of the Csound
  7034. program and assumes the reader is already familiar with the
  7035. Csound program as described in the Csound Users Manual.  Csound
  7036. is primarily intended for the UNIX operating system and hence its
  7037. operation is specified through command line arguments.  The
  7038. Macintosh version of Csound surrounds this mechanism with the
  7039. standard Macintosh user interface primitives, e.g. menus and
  7040. dialog boxes.  After the user specifies the Csound input files
  7041. and options using the Macintosh user interface, Macintosh Csound
  7042. creates the UNIX command line and invokes Csound appropriately. 
  7043. All subsequent Csound output is directed to a console window (or
  7044. optionally to a listing file).  Output sound files are created in
  7045. Digidesign's Sound Designer II format or optionally in AIFF
  7046. format.
  7047.  
  7048. Orchestra and Score file selection dialog
  7049.  
  7050. When Csound is launched, it automatically brings up the main file
  7051. selection dialog. This dialog has fields for the required input
  7052. orchestra and score files, the output sample file, and optionally
  7053. a MIDI file and output listing file. Only the output file name
  7054. may be explicitly typed in, the other fields must be filled by
  7055. clicking on the corresponding Select button, which will bring up
  7056. a standard Macintosh file selection dialog.  Because the
  7057. orchestra and score file names usually differ only in the
  7058. filename extension (".orc" for orchestra files and ".sco" for
  7059. score files), Csound only requires that you select one of the
  7060. two; the other file name will be automatically formed by changing
  7061. the extension appropriately.  If an output file is selected (in
  7062. the Options dialog), then the output file name is similarly
  7063. created with the extension ".snd".
  7064.  
  7065. Users familiar with Csound will recall that Csound expects all
  7066. sound files to live in a single directory called the SFDir (for
  7067. sound file directory).  On UNIX, this directory is specified via
  7068. a UNIX shell environment variable.  On the Macintosh, the user
  7069. must select this directory.  This can be done by clicking on the
  7070. SFDir button next to the output file text item.  This brings up
  7071. the Sound File Directory selection dialog which shows the current
  7072. sound file directory.  When shipped, this will be blank.  The
  7073. sound file directory must be set up properly in order that output
  7074. files may be created.  Clicking on the Select button brings up a
  7075. standard file selection dialog.  Navigate to the directory you
  7076. want to use for sound files, and then click on the Save button. 
  7077. Finally, click on the Save Settings button so that Csound will
  7078. remember this directory when it is run in the future.
  7079.  
  7080. If an input MIDI file is desired, click on the MIDI file
  7081. checkbox.  This brings up a file selection dialog which can be
  7082. used to select a MIDI file.
  7083.  
  7084. If a listing file is desired, click on the listing file checkbox. 
  7085. This bring up a file selection dialog which can be used to
  7086. specify an output listing file.  If a listing file is selected,
  7087. Csound will route almost all output to the listing file.  Certain
  7088. messages will still appear in the console window.
  7089.  
  7090. The Smp Fmt and Options buttons bring up other dialogs for
  7091. setting the Csound output sample format and options,
  7092. respectively.  These are described later in this document.
  7093.  
  7094. After all the files and options have been set up, click on the OK
  7095. button to run Csound.  If the files and options are incorrectly
  7096. set up, Csound will report an error by printing an appropriate
  7097. message to the console window.  After the score file has been
  7098. processed, Csound will display the message "*** PRESS MOUSE
  7099. BUTTON TO EXIT ***".  Pressing the mouse button will cause Csound
  7100. to exit back to the Macintosh Finder.  It is not possible to
  7101. process multiple files without relaunching Csound.
  7102.  
  7103. Clicking on the Cancel button causes the file selection dialog to
  7104. disappear.  The dialog can be brought back by selecting the
  7105. Choose Orchestra and Score menu item in the Csound menu.  Note
  7106. that cancelling the dialog does not cause Csound to forget the
  7107. settings of the various options.  This is particularly useful if
  7108. you want to select extra options explicity by using the "Enter
  7109. command line..." menu item.
  7110.  
  7111. Csound menu
  7112.  
  7113. This section describes the menu items available in the Csound
  7114. menu.  To access the menu items the file selection dialog must be
  7115. cancelled as described above.
  7116.  
  7117. Choose Orchestra and Score...
  7118.  
  7119. Selecting this menu item brings up the main file selection dialog
  7120. described above.
  7121.  
  7122. Options...
  7123.  
  7124. Selecting this menu item brings up the options dialog containing
  7125. checkboxes for each Csound option.  These are each described
  7126. below:
  7127.  
  7128. Note amplitudes
  7129.  
  7130. When checked, causes information regarding note amplitudes to be
  7131. displayed. Corresponds to the -m1 option in UNIX Csound.
  7132.  
  7133. Samples out of range
  7134.  
  7135. When checked, causes information regarding out of range samples
  7136. to be displayed.  Corresponds to the -m2 option in UNIX Csound.
  7137.  
  7138. Warnings
  7139.  
  7140. When checked, causes information regarding out of range samples
  7141. to be displayed.  Corresponds to the -m4 option in UNIX Csound.
  7142.  
  7143. No table graphics
  7144.  
  7145. When checked, suppresses the display of Csound wavetables. 
  7146. Corresponds to the -d option in UNIX Csound.
  7147.  
  7148. Diagnostic messages
  7149.  
  7150. When checked, causes diagnostic messages to be displayed. 
  7151. Corresponds to the -v option in UNIX Csound.
  7152.  
  7153. Initialize processing only
  7154.  
  7155. When checked, causes Csound to only perform initialization of
  7156. orchestras and no other processing.  Corresponds to the -I option
  7157. in UNIX Csound.
  7158.  
  7159. No sound output
  7160.  
  7161. When checked, suppresses the output of a sound file.  Corresponds
  7162. to the -n option in UNIX Csound.
  7163.  
  7164. Change file types
  7165.  
  7166. When checked, Csound will change the file creator field of the
  7167. selected orchestra and score files.  This lets the Macintosh
  7168. Finder know that the files are associated with the Csound
  7169. application.  Thus, if you subsequently double-click on one of
  7170. these files from the Finder, Csound will be executed using the
  7171. selected file as input.
  7172.  
  7173. Output Sample Format...
  7174.  
  7175. Selecting this menu item brings up the output sample format
  7176. dialog which controls the format of the output sample file.  All
  7177. sound files are created as Digidesign Sound Designer II format
  7178. files, unless the -A option is specified in the command line,
  7179. which causes Csound to create AIFF (Audio Interchange File
  7180. Format) files.  The radio buttons select the sample format and
  7181. default to 16-bit integer.  The 8-bit integer, 8-bit a-law, 8-bit
  7182. Œ-law, 16-bit integer, 32-bit integer, and 32-bit float formats
  7183. correspond to the -c, -a, -u, -s, -l, and -f options,
  7184. respectively, in UNIX Csound.  Note that 8-bit a-law format is
  7185. not supported.  If the no header checkbox is checked, this
  7186. suppresses the output of a sound file header; only the raw
  7187. samples are output.  This corresponds to the -h option in UNIX
  7188. Csound.  The blocksize controls how many samples are accumulated
  7189. before writing to the output sample file.  This corresponds to
  7190. the -b option in UNIX Csound.  Note that all input files must be
  7191. either Digidesign Sound Designer II format, AIFF format or raw
  7192. 16-bit samples.
  7193.  
  7194. Sound File Directory...
  7195.  
  7196. Selecting this menu item brings up the sound file directory
  7197. dialog.  This dialog is described above in the file selection
  7198. dialog section.
  7199.  
  7200. Sampled Sound Directory...
  7201.  
  7202. Selecting this menu item brings up the sampled sound directory
  7203. dialog.  This dialog allows the user to specify the directory
  7204. where Csound will look for sampled sound files to be loaded into
  7205. function tables.  This corresponds to the SSDir shell environment
  7206. variable in UNIX Csound.  If no directory is specified, Csound
  7207. will look for sampled sounds in the sound file directory,
  7208. described earlier.
  7209.  
  7210. Enter Command Line...
  7211.  
  7212. Selecting this menu item brings up the command line dialog.  The
  7213. command line dialog is used for directly entering a UNIX command
  7214. line to invoke Csound.  This is useful for specifying obscure
  7215. arguments to Csound which are not otherwise supported in the
  7216. Macintosh interface.  (The AIFF file option -A is one such
  7217. option).  The dialog comes up with a command line that
  7218. corresponds to all currently selected files and options.  The
  7219. command line appears in a Macintosh text edit field for editing. 
  7220. When specifying file name arguments that contain spaces, enclose
  7221. the argument in double-quotes.  Click on OK to invoke Csound with
  7222. the specified arguments, or click on Cancel to exit the dialog
  7223. without executing Csound.
  7224.  
  7225.  
  7226. Save Settings
  7227.  
  7228. Selecting this menu item causes all option settings to be
  7229. remembered for the next time Csound is executed.
  7230.  
  7231. Quit
  7232.  
  7233. Selecting this menu item causes Csound to exit to the Macintosh
  7234. Finder.
  7235.  
  7236. This documentation written on February 10, 1992 by 
  7237. Bill Gardner, MIT Media Laboratory, Music and Cognition Group, 
  7238. 20 Ames Street, Cambridge MA 02139.  
  7239. internet: billg@media-lab.media.mit.edu
  7240.  
  7241.  
  7242. Appendix 6:  Adding your own Cmodules to Csound
  7243.  
  7244.  
  7245. If the existing Csound generators do not suit your needs, you can
  7246. write your own modules in C and add them to the run-time system. 
  7247. When you invoke Csound on an orchestra and score file, the
  7248. orchestra is first read by a table-driven translator 'otran' and
  7249. the instrument blocks converted to coded templates ready for
  7250. loading into memory by 'oload' on request by the score reader. 
  7251. To use your own C-modules within a standard orchestra you need
  7252. only add an entry in otran's table and relink Csound with your
  7253. own code.
  7254.  
  7255. The translator, loader, and run-time monitor will treat your
  7256. module just like any other provided you follow some conventions. 
  7257. You need a structure defining the inputs, outputs and workspace,
  7258. plus some initialization code and some perf-time code.  Let's put
  7259. an example of these in two new files, newgen.h and newgen.c:
  7260.  
  7261.      typedef struct {                   /*  newgen.h  -  define a structure */
  7262.           OPDS      h;                  /* required header */
  7263.           float          *result, *istrt, *incr, *itime, *icontin; /* addr outarg, inargs   */
  7264.           float          curval, vincr;           /* private dataspace */
  7265.           long      countdown;                    /* ditto       */
  7266.      }  RMP;
  7267.  
  7268.      #include "cs.h"                    /*  newgen.c  -  init and perf code */
  7269.      #include "newgen.h"
  7270.  
  7271.      void rampset(p)                    /* at note initialization:     */
  7272.        register  RMP  *p;
  7273.      {
  7274.           if  (*p->icontin == 0.)
  7275.                p->curval = *p->istrt;   /* optionally get new start value */
  7276.           p->vincr = *p->incr / esr;    /* set s-rate increment per sec.   */
  7277.           p->countdown = *p->itime * esr; /* counter for itime seconds     */
  7278.      }
  7279.  
  7280.      void ramp(p)                            /* during note performance:   */
  7281.        register  RMP  *p;
  7282.      {
  7283.           register float *rsltp = p->result;      /* init an output array pointer  */
  7284.           register int nn = ksmps;           /* array size from orchestra */
  7285.           do {
  7286.                *rsltp++ = p->curval;              /* copy current value to ouput */
  7287.                if (--p->countdown >= 0)      /* for the first itime seconds, */
  7288.                     p->curval += p->vincr;   /*   ramp the value  */
  7289.           } while (--nn);
  7290.      }
  7291.  
  7292. Now we add this module to the translator table entry.c, under the
  7293. opcode name rampt:
  7294.  
  7295.      #include "newgen.h"
  7296.      void rampset(), ramp();
  7297.  
  7298.      /*   opcode    dspace    thread    outarg    inargs      isub       ksub     asub    */
  7299.      { "rampt",     S(RMP),   5,   "a", "iiio",     rampset,  NULL,     ramp  },
  7300.  
  7301. Finally we relink Csound to include the new module.  Under Unix
  7302. this means changing the Makefile in three places:
  7303.  
  7304.      1.  Add the name newgen.o to the variable OBJS.
  7305.      2.  Add the name newgen.h as a dependency for entry.o 
  7306.      3.  Create a new dependency,  newgen.o: newgen.h
  7307.  
  7308. Now run 'make csound'.   If your host is a Macintosh, simply add
  7309. newgen.h and newgen.c to one of the Csound segments and invoke
  7310. the C compiler.
  7311.  
  7312. The above actions have added a new generator to the Csound
  7313. language.  It is an audio-rate linear ramp function which
  7314. modifies an input value at a user-defined slope for some period. 
  7315. A ramp can optionally continue from the previous note's last
  7316. value.  The Csound manual entry would look like:
  7317.  
  7318.           ar   rampt     istart,  islope, itime [,  icontin]
  7319.  
  7320. istart - beginning value of an audio-rate linear ramp. 
  7321. Optionally overridden by a continue flag.
  7322.  
  7323. islope - slope of ramp, expressed as the y-interval change per 
  7324. second.
  7325.  
  7326. itime - ramp time in seconds, after which the value is held for
  7327. the remainder of the note.
  7328.  
  7329. icontin (optional) - continue flag.  If zero, ramping will
  7330. proceed from input istart .  If non-zero, ramping will proceed
  7331. from the last value of the previous note.  The default value is
  7332. zero.
  7333.  
  7334. The file newgen.h includes a one-line list of output and input
  7335. parameters.  These are the ports through which the new generator
  7336. will communicate with the other generators in an instrument. 
  7337. Communication is by address, not value, and this is a list of
  7338. pointers to floats.  There are no restrictions on names, but the
  7339. input-output argument types are further defined by character
  7340. strings in entry.c (inargs, outargs).   Inarg types are commonly
  7341. x, a, k, and i, in the normal Csound manual conventions;  also
  7342. available are o (optional, defaulting to 0), p (optional,
  7343. defaulting to 1).  Outarg types include a, k, i and s (asig or
  7344. ksig).  It is important that all listed argument names be
  7345. assigned a corresponding argument type in entry.c.  Also, i-type
  7346. args are valid only at initialization time, and other-type args
  7347. are available only at perf time.  Subsequent lines in the RMP
  7348. structure declare the work space needed to keep the code
  7349. re-entrant.  These enable the module to be used multiple times in
  7350. multiple instrument copies while preserving all data.
  7351.  
  7352. The file newgen.c contains two subroutines, each called with a
  7353. pointer to the uniquely allocated RMP structure and its data. 
  7354. The subroutines can be of three types: note initialization,
  7355. k-rate signal generation, a-rate signal generation.  A module
  7356. normally requires two of theseעinitialization, and either k-rate
  7357. or a-rate subroutinesעwhich become inserted in various threaded
  7358. lists of runnable tasks when an instrument is activated.  The
  7359. thread-types appear in entry.c in two forms:  isub, ksub and asub
  7360. names;  and a threading index which is the sum of isub=1, ksub=2,
  7361. asub=4.  The code itself may reference global variables defined
  7362. in cs.h and oload.c, the most useful of which are:
  7363.           float     esr       user-defined sampling rate
  7364.           float     ekr       user-defined control rate
  7365.           float     ensmps    user-defined ksmps
  7366.           int  ksmps          user-defined ksmps
  7367.           int  nchnls         user-defined nchnls
  7368.           int  odebug    command-line -v flag
  7369.           int  initonly  command-line -I flag
  7370.           int  msglevel  command-line -m level
  7371.           float     pi, twopi obvious constants
  7372.           float     tpidsr         twopi / esr
  7373.           float     sstrcod   special code for string arguments
  7374.  
  7375. Function tables
  7376.  
  7377. To access stored function tables, special help is available.  The
  7378. newly defined structure should include a pointer
  7379.                     FUNC        *ftp;
  7380. initialized by the statement
  7381.                     ftp = ftpfind(p->ifuncno);
  7382.  
  7383. where float *ifuncno is an i-type input argument containing the
  7384. ftable number.  The stored table is then at ftp->ftable, and
  7385. other data such as length, phase masks, cps-to-incr converters,
  7386. are also accessed from this pointer.  See the FUNC structure in
  7387. cs.h, the ftfind() code in fgens.c, and the code for oscset() and
  7388. koscil() in ugens2.c.
  7389.  
  7390. Additional space
  7391.  
  7392. Sometimes the space requirement of a module is too large to be
  7393. part of a structure (upper limit 65535 bytes), or it is dependent
  7394. on an i-arg value which is not known until initialization. 
  7395. Additional space can be dynamically allocated and properly
  7396. managed by including the line
  7397.  
  7398.                     AUXCH      auxch;
  7399.  
  7400. in the defined structure (*p), then using the following style of
  7401. code in the init module:
  7402.  
  7403.                if (p->auxch.auxp == NULL)
  7404.                     auxalloc(npoints * sizeof(float), &p->auxch);
  7405.  
  7406. The address of this auxilliary space is kept in a chain of such
  7407. spaces belonging to this instrument, and is automatically managed
  7408. while the instrument is being duplicated or garbage-collected
  7409. during performance.  The assignment
  7410.  
  7411.                char *auxp = p->auxch.auxp;
  7412.  
  7413. will find the allocated space for init-time and perf-time use. 
  7414. See the LINSEG structure in ugens1.h and the code for lsgset()
  7415. and klnseg() in ugens1.c.
  7416.  
  7417. File sharing
  7418.  
  7419. When accessing an external file often, or doing it from multiple
  7420. places, it is often efficient to read the entire file into
  7421. memory.  This is accomplished by including the line
  7422.  
  7423.                     MEMFIL    *mfp;
  7424.  
  7425. in the defined structure (*p), then using the following style of
  7426. code in the init module:
  7427.  
  7428.                if (p->mfp == NULL)
  7429.                     p->mfp = ldmemfile(filname);
  7430.  
  7431. where char *filname is a string name of the file requested.  The
  7432. data read will be found between 
  7433.  
  7434.      (char *)  p->mfp->beginp;          and       (char *) p->mfp->endp;
  7435.  
  7436. Loaded files do not belong to a particular instrument, but are
  7437. automatically shared for multiple access.  See the ADSYN
  7438. structure in ugens3.h and the code for adset() and adsyn() in
  7439. ugens3.c.
  7440.  
  7441. String arguments
  7442.  
  7443. To permit a quoted string input argument (float *ifilnam, say) in
  7444. our defined structure (*p), assign it the argtype S in entry.c,
  7445. include another member char *strarg in the structure, insert a
  7446. line
  7447.  
  7448.                     TSTRARG( "rampt",  RMP)  \
  7449.  
  7450. in the file oload.h, and include the following code in the init
  7451. module:
  7452.  
  7453.                if (*p->ifilnam == sstrcod)
  7454.                     strcpy(filename, unquote(p->strarg));
  7455.  
  7456. See the code for adset() in ugens3.c, lprdset() in ugens5.c, and
  7457. pvset() in ugens8.c.
  7458.  
  7459. Appendix 7:  A CSOUND QUICK REFERENCE 
  7460.  
  7461. VALUE CONVERTERS 
  7462.  
  7463.                ftlen(x)  (init-rate args only) 
  7464.                int(x)         (init- or control-rate args only) 
  7465.                frac(x)        "         "
  7466.                dbamp(x)       "         "
  7467.                i(x)      (control-rate arg; only) 
  7468.                abs(x)    (no rate restriction) 
  7469.                exp(x)         "         "
  7470.                log(x)         "         "
  7471.                sqrt(x)        "         "
  7472.                sin(x)         "         "
  7473.                cos(x)         "         "
  7474.                ampdb(x)       "         "
  7475.  
  7476. PITCH CONVERTERS 
  7477.  
  7478.                octpch(pch)    (init- or control-rate args only) 
  7479.                pchoct(oct)         "         "
  7480.                cpspch(pch)         "         "
  7481.                octcps(cps)         "         "
  7482.                cpsoct(oct)    (no rate restriction) 
  7483.  
  7484. PROGRAM CONTROL 
  7485.  
  7486.                igoto          label 
  7487.                tigoto    label 
  7488.                kgoto     label 
  7489.                goto      label 
  7490.                if        ia R ib igoto label 
  7491.                if        ka R kb kgoto label 
  7492.                if        ia R ib goto label 
  7493.                timout    istrt, idur, label 
  7494.  
  7495. MIDI CONVERTERS
  7496.  
  7497.           iamp ampmidi   iscal[, ifn]
  7498.           kaft aftouch   iscal
  7499.           kchpr     chpress   iscal
  7500.           kbend     pchbend   iscal
  7501.           ival midictrl  inum
  7502.           kval midictrl  inum
  7503.  
  7504.  
  7505. SIGNAL GENERATORS 
  7506.  
  7507.           kr   line      ia, idur1, ib
  7508.           ar   line      ia, idur1, ib
  7509.           kr   expon     ia, idur1, ib 
  7510.           ar   expon     ia, idur1, ib 
  7511.           kr   linseg    ia, idur1, ib[, idur2, ic[...]] 
  7512.           ar   linseg    ia, idur1, ib[, idur2, ic[...]] 
  7513.           kr   expseg    ia, idur1, ib[, idur2, ic[...]] 
  7514.           ar   expseg    ia, idur1, ib[, idur2, ic[...]] 
  7515.  
  7516.           kr   phasor    kcps[, iphs]
  7517.           ar   phasor    xcps[, iphs] 
  7518.  
  7519.           ir   table          indx, ifn[, ixmode][, ixoff][, iwrap]
  7520.           ir   tablei         indx, ifn[, ixmode][, ixoff][, iwrap]
  7521.           kr   table          kndx, ifn[, ixmode][, ixoff][, iwrap]
  7522.           kr   tablei         kndx, ifn[, ixmode][, ixoff][, iwrap]
  7523.           ar   table          andx, ifn[, ixmode][, ixoff][, iwrap]
  7524.           ar   tablei         andx, ifn[, ixmode][, ixoff][, iwrap]
  7525.           kr   oscil1    idel, kamp, idur, ifn
  7526.           kr   oscil1i   idel, kamp, idur, ifn
  7527.  
  7528.           kr   oscil          kamp, kcps, ifn[, iphs]
  7529.           kr   oscili         kamp, kcps, ifn[, iphs]
  7530.           ar   oscil          xamp, xcps, ifn[, iphs]
  7531.           ar   oscili         xamp, xcps, ifn[, iphs]
  7532.           ar   foscil    xamp, kcps, kcar, kmod, kndx, ifn[, iphs]
  7533.           ar   foscili   xamp, kcps, kcar, kmod, kndx, ifn[, iphs]
  7534.            ar1 [,ar2]    loscil         xamp, kcps, ifn[, ibas][, imod1,ibeg1,iend1]
  7535.                                         [, imod2,ibeg2,iend2]
  7536.  
  7537.           ar   buzz      xamp, xcps, knh, ifn[, iphs]
  7538.           ar   gbuzz     xamp, xcps, knh, kih, kr, ifn[, iphs]
  7539.  
  7540.           ar   adsyn     kamod, kfmod, ksmod, ifilcod 
  7541.           ar   pvoc      ktimpnt, kfmod, ifilcod[, ispecwp]
  7542.  
  7543.           ar   fof       xamp, xfund, xform, koct, kband, kris, kdur, kdec,
  7544.                               iolaps, ifna, ifnb, itotdur[, iphs][, ifmode] 
  7545.           ar   pluck     kamp, kcps, icps, ifn, imeth [, iparm1, iparm2] 
  7546.  
  7547.           kr   rand      xamp[, iseed]
  7548.           kr   randh     kamp, kcps[, iseed]
  7549.           kr   randi          kamp, kcps[, iseed]
  7550.           ar   rand      xamp[, iseed]
  7551.           ar   randh     xamp, xcps[, iseed]
  7552.           ar   randi          xamp, xcps[, iseed]
  7553.  
  7554.  
  7555. SIGNAL MODIFIERS
  7556.  
  7557.           kr   linen          kamp, irise, idur, idec
  7558.           ar   linen          xamp, irise, idur, idec
  7559.           kr   linenr    kamp, irise, idec, iatdec
  7560.           ar   linenr    xamp, irise, idec, iatdec
  7561.           kr   envlpx    kamp, irise, idur, idec, ifn, iatss, iatdec[, ixmod]
  7562.           ar   envlpx    xamp, irise, idur, idec, ifn, iatss, iatdec[, ixmod]
  7563.  
  7564.           kr   port      ksig, ihtim[, isig]
  7565.           ar   tone      asig, khp[, istor]
  7566.           ar   atone          asig, khp[, istor]
  7567.           ar   reson          asig, kcf, kbw[, iscl, istor]
  7568.           ar   areson    asig, kcf, kbw[, iscl, istor]
  7569.  
  7570.  
  7571. krmsr,krmso,kerr,kcpslpread   ktimpnt, ifilcod[, inpoles][,ifrmrate] 
  7572.           ar   lpreson   asig 
  7573.           ar   lpfreson  asig, kfrqratio 
  7574.  
  7575.  
  7576.           kr   rms       asig[, ihp, istor]
  7577.           nr   gain      asig, krms[, ihp, istor]
  7578.           ar   balance   asig, acomp[, ihp, istor]
  7579.           kr   downsamp  asig[, iwlen]
  7580.           ar   upsamp    ksig 
  7581.           ar   interp    ksig[, istor]
  7582.           kr   integ          ksig[, istor]
  7583.           ar   integ          asig[, istor]
  7584.           kr   diff      ksig[, istor]
  7585.           ar   diff      asig[, istor]
  7586.           kr   samphold  xsig, kgate[, ival, ivstor]
  7587.           ar   samphold  asig, xgate[, ival, ivstor]
  7588.  
  7589.  
  7590.           ar   delayr    idlt[, istor]
  7591.                delayw    asig
  7592.           ar   delay          asig, idlt[, istor]
  7593.           ar   delay1    asig[, istor]
  7594.           ar   deltap    kdlt
  7595.           ar   deltapi   xdlt 
  7596.  
  7597.  
  7598.           ar   comb      asig, krvt, ilpt[, istor]
  7599.           ar   alpass    asig, krvt, ilpt[, istor]
  7600.           ar   reverb    asig, krvt[, istor]
  7601.  
  7602. OPERATIONS USING SPECTRAL DATA TYPES
  7603.  
  7604.           dsig octdown   xsig, iocts, isamps[, idisprd]
  7605.           wsig noctdft   dsig, iprd, ifrqs, iq[, ihann, idbout,
  7606. idsines]
  7607.           wsig specscal  wsigin, ifscale, ifthresh
  7608.           wsig specaddm  wsig1, wsig2[, imul2]
  7609.           wsig specdiff  wsigin
  7610.           wsig specaccm  wsigin
  7611.           wsig specfilt  wsigin, ifhtim
  7612.                specdisp  wsig, iprd[, iwtflg]
  7613.           ksum specsum   wsig[, interp]
  7614.  
  7615.  
  7616. SENSING & CONTROL
  7617.  
  7618.           ktemp     tempest   kin, iprd, imindur, imemdur, ihp,
  7619. ithresh, ihtim, ixfdbak, 
  7620.                               istartempo, ifn[, idisprd, itweek] 
  7621.  
  7622.           kx, ky    xyin      iprd, ixmin, ixmax, iymin, iymax[,
  7623. ixinit, iyinit] 
  7624.                tempo     ktempo, istartempo 
  7625.  
  7626. SOUND INPUT & OUTPUT
  7627.  
  7628.           a1   in 
  7629.           a1, a2    ins 
  7630.      a1, a2, a3, a4 inq 
  7631.           a1   soundin   ifilcod[, iskptim][, iformat] 
  7632.           a1, a2    soundin   ifilcod[, iskptim][, iformat] 
  7633.      a1, a2, a3, a4 soundin   ifilcod[, iskptim][, iformat] 
  7634.                out       asig 
  7635.                outs1          asig 
  7636.                outs2          asig 
  7637.                outs      asig1, asig2
  7638.  
  7639.                outq1     asig 
  7640.                outq2     asig
  7641.                outq3     asig 
  7642.                outq4     asig 
  7643.                outq      asig1, asig2, asig3, asig4 
  7644.  
  7645.      a1, a2, a3, a4 pan       asig, kx, ky, ifn[, imode][,ioffset] 
  7646.  
  7647. SIGNAL DISPLAY
  7648.  
  7649.                print          iarg[, iarg,...] 
  7650.                display   xsig, iprd[, iwtflg] 
  7651.                dispfft   xsig, iprd, iwsiz[, iwtyp][, idbouti][,iwtflg] 
  7652.  
  7653.  
  7654. END OF Csound MANUAL
  7655.